Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Apple is not convertible to itself (clang 3.8.0)
#include <type_traits> #include <functional> class Apple; template <class From, class To> using EnableIfConvertible = typename std::enable_if<std::is_convertible<From, To>::value>::type; // === class Basket ==================================================================================================== class Basket { public: Basket (const Apple&) {} Basket (Apple&&) {} template <class A, class = EnableIfConvertible<A, Apple>> Basket (A&& a) : Basket (Apple (a)) {} }; // === class Apple ===================================================================================================== class Apple { public: Apple (int) {} }; // === Conversion tryout =============================================================================================== Basket Fun () { return 1; } // === main () ========================================================================================================= int main () { std::function<Apple ()> fun = [] () -> Apple { return 1; }; // does not compile static_assert (std::is_convertible<Apple, Apple>::value, "We are in trouble."); // does not compile }
run
|
edit
|
history
|
help
0
Struct memory ordering
wasm test for node
mine
Saam hash example
chakib
simple in-memory b-tree
Copy uint64 data into uint32 with padding
SceneGraph Interviewee Task
Result of not joining thread in main()
Standard Template Library