Created
December 28, 2012 11:05
-
-
Save hisui/4396877 to your computer and use it in GitHub Desktop.
constexprはランタイム時にも呼び出しできるから、引数の値をテンプレート引数に渡すことは出来ない件(´;ω;`)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <type_traits> | |
#include <iostream> | |
extern void *enabler; | |
// 文字のリスト | |
template<char H, typename T> | |
struct cons {}; | |
struct nil {}; | |
template<size_t N, size_t I = 0 | |
, typename std::enable_if<I == N>::type *& = enabler> | |
constexpr auto make_str(char const(&a)[N]) -> nil; | |
template<size_t N, size_t I = 0 | |
, typename std::enable_if<I != N>::type *& = enabler> | |
constexpr auto make_str(char const(&a)[N]) | |
-> cons<a[I],decltype(make_str<N,I+1>(a))>; // これはNG... | |
int main() | |
{ | |
typedef decltype(make_str("unko")) str; // これがやりたかったのだけど | |
auto &info = typeid(str); | |
std::cerr << info.name() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment