• R/O
  • SSH
  • HTTPS

eirrepo: Commit


Commit MetaInfo

Revision91 (tree)
Time2018-05-02 07:41:40
Authorquiret

Log Message

- added helpful ConstructArgs method to factories to avoid having to create own constructoid for each class (it passes arguments using C++17 std::apply feature)

Change Summary

Incremental Difference

--- common/sdk/MemoryUtils.h (revision 90)
+++ common/sdk/MemoryUtils.h (revision 91)
@@ -2040,6 +2040,37 @@
20402040 return resultObj;
20412041 }
20422042
2043+ template <typename allocatorType, typename... Args>
2044+ inline classType* ConstructArgs( allocatorType& memAllocator, Args... theArgs )
2045+ {
2046+ // We try saving the arguments in a struct and then unpacking them on call
2047+ // to the constructor, using C++17 std::apply!
2048+
2049+ struct packed_args_constr
2050+ {
2051+ inline packed_args_constr( Args... theArgs ) : data( std::move( theArgs )... )
2052+ {
2053+ return;
2054+ }
2055+
2056+ inline classType* Construct( void *mem ) const
2057+ {
2058+ auto helper = [&]( Args... theArgs )
2059+ {
2060+ return new (mem) classType( std::move( theArgs )... );
2061+ };
2062+
2063+ return std::apply( helper, std::move( data ) );
2064+ }
2065+
2066+ std::tuple <Args...> data;
2067+ };
2068+
2069+ packed_args_constr constr( std::move( theArgs )... );
2070+
2071+ return ConstructTemplate( memAllocator, constr );
2072+ }
2073+
20432074 template <typename constructorType>
20442075 inline classType* ClonePlacementEx( void *classMem, const classType *srcObject, const constructorType& constructor )
20452076 {
Show on old repository browser