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
Maze problem solution
Test size_t
C++ Operator Overloading
sfinae
Fun with Pointers #2
Example of custom deleter to manage a resource.
hello world 3
Erase a std::unordered_map::local_iterator by key
Combination
Set sub sequences.