user1095108 / generic Goto Github PK
View Code? Open in Web Editor NEWLicense: The Unlicense
License: The Unlicense
Hi, this is not a real issue.
I've been following your library since before you moved it to Github. I was wondering why you moved the delegate class to be obsolete?
Cheers
Hi,
Currently gnr::forwarder
cannot take a std::bind
object, since the following static_assert static_assert(std::is_trivially_copyable<functor_type>{},""
(ref) will issue an error.
Question: is that static_assert
needed?
Thanks.
Details:
If you try the following code
https://github.com/user706/code_generic/blob/master/code/intern/forwarder_ex2.cpp
building as follows:
cd /tmp
git clone https://github.com/user706/code_generic
cd code_generic
mkdir -p build
cd build
cmake .. # need at least cmake 3.8.2, which understands CMAKE_CXX_STANDARD of 17 https://cmake.org/cmake/help/v3.8/prop_tgt/CXX_STANDARD.html#prop_tgt:CXX_STANDARD
make -j8
./code/intern/forwarder_ex2
and then change the following snippet https://github.com/user706/code_generic/blob/master/code/intern/forwarder_ex2.cpp#L7
to use gnr::forwarder
, as follows
// uncomment _one_ of the two lines below
//template <typename T, std::size_t N = 0> using FF = std::function<T>;
template <typename T, std::size_t N = default_size> using FF = gnr::forwarder<T, N>; // this only works if commenting out lines with std::bind below, or changing forwarder.hpp
then you'll find that a rebuild with make
will fail as follows
In file included from /tmp/code_generic/code/intern/forwarder_ex2.cpp:2:0:
/tmp/code_generic/code/extern/generic_cmake/generic/forwarder.hpp: In instantiation of ‘void gnr::forwarder<R(A ...), N, NE>::assign(F&&) [with F = std::_Bind<void (*(int))(int)>; R = void; A = {}; long unsigned int N = 32ul; bool NE = false]’:
/tmp/code_generic/code/extern/generic_cmake/generic/forwarder.hpp:77:11: required from ‘gnr::forwarder<R(A ...), N, NE>::forwarder(F&&) [with F = std::_Bind<void (*(int))(int)>; <template-parameter-2-2> = void; R = void; A = {}; long unsigned int N = 32ul; bool NE = false]’
/tmp/code_generic/code/intern/forwarder_ex2.cpp:46:60: required from here
/tmp/code_generic/code/extern/generic_cmake/generic/forwarder.hpp:123:5: error: static assertion failed: functor not trivially copyable
static_assert(std::is_trivially_copyable<functor_type>{},
^~~~~~~~~~~~~
/tmp/code_generic/code/extern/generic_cmake/generic/forwarder.hpp:128:11: error: cannot convert ‘gnr::forwarder<R(A ...), N, NE>::assign(F&&) [with F = std::_Bind<void (*(int))(int)>; R = void; A = {}; long unsigned int N = 32ul; bool NE = false]::<lambda(void*)>’ to ‘void (*)(void*)’ in assignment
stub_ = [](void* const ptr, A&&... args) noexcept(noexcept(NE)) -> R
/tmp/code_generic/code/extern/generic_cmake/generic/forwarder.hpp: In instantiation of ‘void gnr::forwarder<R(A ...), N, NE>::assign(F&&) [with F = std::_Bind<std::_Mem_fn<void (Foo::*)(int) const>(Foo, std::_Placeholder<1>)>; R = void; A = {int}; long unsigned int N = 32ul; bool NE = false]’:
/tmp/code_generic/code/extern/generic_cmake/generic/forwarder.hpp:77:11: required from ‘gnr::forwarder<R(A ...), N, NE>::forwarder(F&&) [with F = std::_Bind<std::_Mem_fn<void (Foo::*)(int) const>(Foo, std::_Placeholder<1>)>; <template-parameter-2-2> = void; R = void; A = {int}; long unsigned int N = 32ul; bool NE = false]’
/tmp/code_generic/code/intern/forwarder_ex2.cpp:61:72: required from here
/tmp/code_generic/code/extern/generic_cmake/generic/forwarder.hpp:123:5: error: static assertion failed: functor not trivially copyable
static_assert(std::is_trivially_copyable<functor_type>{},
^~~~~~~~~~~~~
/tmp/code_generic/code/extern/generic_cmake/generic/forwarder.hpp:128:11: error: cannot convert ‘gnr::forwarder<R(A ...), N, NE>::assign(F&&) [with F = std::_Bind<std::_Mem_fn<void (Foo::*)(int) const>(Foo, std::_Placeholder<1>)>; R = void; A = {int}; long unsigned int N = 32ul; bool NE = false]::<lambda(void*, int&&)>’ to ‘void (*)(void*, int&&)’ in assignment
stub_ = [](void* const ptr, A&&... args) noexcept(noexcept(NE)) -> R
/tmp/code_generic/code/extern/generic_cmake/generic/forwarder.hpp: In instantiation of ‘void gnr::forwarder<R(A ...), N, NE>::assign(F&&) [with F = std::_Bind<std::_Mem_fn<void (Foo::*)(int) const>(const Foo*, std::_Placeholder<1>)>; R = void; A = {int}; long unsigned int N = 32ul; bool NE = false]’:
/tmp/code_generic/code/extern/generic_cmake/generic/forwarder.hpp:77:11: required from ‘gnr::forwarder<R(A ...), N, NE>::forwarder(F&&) [with F = std::_Bind<std::_Mem_fn<void (Foo::*)(int) const>(const Foo*, std::_Placeholder<1>)>; <template-parameter-2-2> = void; R = void; A = {int}; long unsigned int N = 32ul; bool NE = false]’
/tmp/code_generic/code/intern/forwarder_ex2.cpp:65:73: required from here
/tmp/code_generic/code/extern/generic_cmake/generic/forwarder.hpp:123:5: error: static assertion failed: functor not trivially copyable
static_assert(std::is_trivially_copyable<functor_type>{},
^~~~~~~~~~~~~
/tmp/code_generic/code/extern/generic_cmake/generic/forwarder.hpp:128:11: error: cannot convert ‘gnr::forwarder<R(A ...), N, NE>::assign(F&&) [with F = std::_Bind<std::_Mem_fn<void (Foo::*)(int) const>(const Foo*, std::_Placeholder<1>)>; R = void; A = {int}; long unsigned int N = 32ul; bool NE = false]::<lambda(void*, int&&)>’ to ‘void (*)(void*, int&&)’ in assignment
stub_ = [](void* const ptr, A&&... args) noexcept(noexcept(NE)) -> R
code/intern/CMakeFiles/forwarder_ex2.dir/build.make:62: recipe for target 'code/intern/CMakeFiles/forwarder_ex2.dir/forwarder_ex2.cpp.o' failed
make[2]: *** [code/intern/CMakeFiles/forwarder_ex2.dir/forwarder_ex2.cpp.o] Error 1
CMakeFiles/Makefile2:186: recipe for target 'code/intern/CMakeFiles/forwarder_ex2.dir/all' failed
make[1]: *** [code/intern/CMakeFiles/forwarder_ex2.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
The offending lines, are the ones using std::bind
--- here, here and here.
However if one removes the following static_assert
static_assert(std::is_trivially_copyable<functor_type>{},
"functor not trivially copyable");
from code/extern/generic_cmake/generic/forwarder.hpp
(ref), then it will compile.
Question: is that static_assert
needed?
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.