Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
MPL 2-1
//clang 3.8.0 /* 2-1. Write a ternary metafunction replace_type<c,x,y> that takes an arbitrary compound type c as its first parameter, and replaces all occurrences of a type x within c with y: typedef replace_type< void*, void, int >::type t1; // int* typedef replace_type< int const*[10] ,int const , long >::type t2; // long* [10] typedef replace_type< char& (*)(char&) , char& , long& >::type t3; // long& (*)(long&) You can limit the function types you operate on to those with fewer than two arguments. */ #include <iostream> #include <deque> #include <string> #include <map> #include <unordered_map> #include <vector> #include <algorithm> #include <memory> #include <iterator> #include <stack> #include <set> using namespace std; #include <boost/type_traits.hpp> #include <boost/mpl/if.hpp> #include <type_traits> #include <typeinfo> #ifndef _MSC_VER # include <cxxabi.h> #endif #include <memory> #include <string> #include <cstdlib> namespace { template <class T> std::string type_name() { typedef typename std::remove_reference<T>::type TR; std::unique_ptr<char, void(*)(void*)> own ( #ifndef _MSC_VER abi::__cxa_demangle(typeid(TR).name(), nullptr, nullptr, nullptr), #else nullptr, #endif std::free ); std::string r = own != nullptr ? own.get() : typeid(TR).name(); if (std::is_const<TR>::value) r += " const"; if (std::is_volatile<TR>::value) r += " volatile"; if (std::is_lvalue_reference<T>::value) r += "&"; else if (std::is_rvalue_reference<T>::value) r += "&&"; return r; } } // just for printing // ternary template <typename C, typename X, typename Y> struct { // stupid msg }; int main() { }
run
|
edit
|
history
|
help
0
Non type template argument
ternary test
sfinae
Narrowing error
Recursive Enumeration Example
problem_name_1
Copy uint64 data into uint32 with padding
Wrapper to pass shared_ptr to &, const &, *, const * through std::bind.
back_inserter example
AnnotateAttr templated test