Boost::Interprocess - using variadic template args with managed_shared_memory::construct()
Hi, I'm trying to write a wrapper over some of boost::interprocess and I want to have a function like this: template <typename T, typename... Args> T* Wrapper::createStruct(const std::string& name, Args&&... args) { return m_shm->construct<T>(name.c_str())(std::forward<Args>(args)...); } This fails to compile as it seems boost::interprocess uses its own varargs scheme when I try to create the following struct in the SHM through this wrapper function: struct Custom { Custom(int a, int b) : m_a(a), m_b(b) { } int a; int b; } int main() { ... Custom* c = shm->createStruct("Custom", 1, 2); } The error message: /usr/include/boost/interprocess/detail/named_proxy.hpp:79:7: error: no matching function for call to ‘test_sharedmemory::sharedmemory_custom::test_method()::Custom::Custom()’ { new((void*)mem)T(boost::forward<Args>(get<IdxPack>(args_))...); } ^ /usr/include/boost/interprocess/detail/named_proxy.hpp:79:7: note: candidates are: /home/james/dev/infinityplus/test/common/shm/sharedmemory/main.cpp:136:7: note: test_sharedmemory::sharedmemory_custom::test_method()::Custom::Custom(int, int) Custom(int one, int two) ^ /home/james/dev/infinityplus/test/common/shm/sharedmemory/main.cpp:136:7: note: candidate expects 2 arguments, 0 provided Is there any way I can get this to work? I'd rather my wrapper's interface used std only. boost 1.55 c++11 g++ 4.8.2 TIA, James
El 28/04/2014 12:49, james escribió:
Hi,
I'm trying to write a wrapper over some of boost::interprocess and I want to have a function like this:
template <typename T, typename... Args> T* Wrapper::createStruct(const std::string& name, Args&&... args) { return m_shm->construct<T>(name.c_str())(std::forward<Args>(args)...); }
I can't see why the arguments are not forwarded. Could you elaborate a compilable little test case to reproduce the problem? Best, Ion
participants (2)
-
Ion Gaztañaga
-
james