2016-03-25 10 views
0

誰かがここで何が起こっているのか説明できますか? GCCからの出力5.2:std :: string型がタプルで失われた

#include <iostream> 
#include <tuple> 
#include <string> 
#include <typeinfo> 

template <typename... Args> 
void foo (Args&&... args) { 
    std::tuple<Args...> t = std::tie(args...); 
    std::cout << std::is_same<int, std::tuple_element_t<0, decltype(t)>>::value << '\n'; // true 
    std::cout << std::is_same<std::string, std::tuple_element_t<1, decltype(t)>>::value << '\n'; // false 
    std::cout << typeid(std::tuple_element_t<1, decltype(t)>).name() << '\n'; // A3_C (what's this???) 
} 

int main() { 
    foo (5, "hi"); 
} 

なぜstd :: string型が失われ、代わりに何が変わるのですか?

答えて

4

"string"は - const char[N]配列、ないstd::stringです。この場合const char[] = {'h', 'i', '\0'} -> const char[3] ->char(A3_C)の要素。 使用std::string("hi")は、文字列を作るか、またはユーザーリテラルを有効にして書くこと"hi"s

1

"hi"(文字列リテラル)タイプconst char[3]、ではないのですstd::string

関連する問題