• R/O
  • SSH
  • HTTPS

eirrepo: Commit


Commit MetaInfo

Revision386 (tree)
Zeit2021-09-15 22:57:05
Autorquiret

Log Message

- optimized away move-constructions from eir::Map
- added eir::constructible_from, a friend-boundary resistant version of C++20 std::constructible_from (might turn obsolete in the case that the C++ team fixes it)

Ändern Zusammenfassung

Diff

--- common/sdk/Allocation.h (revision 385)
+++ common/sdk/Allocation.h (revision 386)
@@ -16,6 +16,11 @@
1616 namespace eir
1717 {
1818
19+// Friendship resistant replacement for std::constructible_from (it is buggy as shit).
20+template <typename T, typename... cArgTypes>
21+concept constructible_from =
22+ requires ( cArgTypes&&... cArgs ) { new T( std::forward <cArgTypes> ( cArgs )... ); };
23+
1924 // A very special pass-in just for creation with the allocator initialization.
2025 enum class constr_with_alloc
2126 {
@@ -78,6 +83,7 @@
7883
7984 // Constructs an object with the help of a static memory allocator.
8085 template <typename structType, StaticMemoryAllocator allocatorType, typename exceptMan = eir::DefaultExceptionManager, typename... Args>
86+ requires constructible_from <structType, Args...>
8187 inline structType* static_new_struct( void *refMem, Args&&... theArgs )
8288 {
8389 // Attempt to allocate a block of memory for bootstrapping.
@@ -113,6 +119,12 @@
113119
114120 // Constructs an object using an object memory allocator.
115121 template <typename structType, typename exceptMan = eir::DefaultExceptionManager, MemoryAllocator allocatorType, typename... Args>
122+ //requires constructible_from <structType, Args...>
123+// There are multiple issues of why I cannot use a requires-clause for this function template:
124+// 1) there is no way to directly befriend a function template without prior declaration as friend.
125+// 2) I tried and failed to write a befriending of a function template that comes with a requires-clause.
126+// Until the C++ standards or compilers team fixes it, I will just leave it out... Would be nice to
127+// have though.
116128 inline structType* dyn_new_struct( allocatorType& allocMan, void *refMem, Args&&... theArgs )
117129 {
118130 // Attempt to allocate a block of memory for bootstrapping.
--- common/sdk/Map.h (revision 385)
+++ common/sdk/Map.h (revision 386)
@@ -28,6 +28,7 @@
2828 #include "avlsetmaputil.h"
2929
3030 #include <type_traits>
31+#include <tuple>
3132
3233 // TODO: add object allocator support for eir::Map.
3334
@@ -78,11 +79,17 @@
7879 private:
7980 // Not available to things that just use Map.
8081 // But the friend class does have access.
81- inline Node( keyType key, valueType value )
82- : key( std::move( key ) ), value( std::move( value ) )
82+ template <std::convertible_to <keyType> cKeyType, std::convertible_to <valueType> cValueType>
83+ inline Node( cKeyType&& key, cValueType&& value )
84+ : key( std::forward <cKeyType> ( key ) ), value( std::forward <cValueType> ( value ) )
8385 {
8486 return;
8587 }
88+ template <typename... valueArgs> requires ( eir::constructible_from <valueType, valueArgs...> )
89+ inline Node( keyType key, std::tuple <valueArgs...>&& vargs ) : key( std::move( key ) ), value( std::make_from_tuple <valueType> ( std::move( vargs ) ) )
90+ {
91+ return;
92+ }
8693 inline ~Node( void ) noexcept = default;
8794
8895 keyType key;
@@ -159,7 +166,7 @@
159166 }
160167 }
161168
162- template <std::convertible_to <keyType> cKeyType, std::convertible_to <valueType> cValueType>
169+ template <typename cKeyType, typename cValueType> //requires ( eir::constructible_from <Node, cKeyType, cValueType> )
163170 static AINLINE Node* NewNode( Map *refMem, MapAVLTree& workTree, cKeyType&& key, cValueType&& value )
164171 {
165172 Node *newNode = eir::dyn_new_struct <Node, exceptMan> ( refMem->data.opt(), refMem, std::forward <cKeyType> ( key ), std::forward <cValueType> ( value ) );
@@ -633,7 +640,7 @@
633640 return findNode->value;
634641 }
635642
636- return NewNode( this, this->data.avlKeyTree, std::forward <queryType> ( key ), valueType() )->value;
643+ return NewNode( this, this->data.avlKeyTree, std::forward <queryType> ( key ), std::tuple() )->value;
637644 }
638645
639646 // Similar to the operator [] but it allows for non-default-construction of
@@ -646,8 +653,8 @@
646653 {
647654 return findNode->value;
648655 }
649-
650- return NewNode( this, this->data.avlKeyTree, std::forward <queryType> ( key ), valueType( std::forward <constrArgs> ( cargs )... ) )->value;
656+
657+ return NewNode( this, this->data.avlKeyTree, std::forward <queryType> ( key ), std::tuple <constrArgs&&...> ( std::forward <constrArgs> ( cargs )... ) )->value;
651658 }
652659
653660 // Returns the node from a reference-to-value, in constant time.
Show on old repository browser