简体   繁体   中英

std::underlying_type support in clang++

I assume C++ Compound type alterations support should be enabled in clang++ by -std=c++11 switch. But I'm unable to compile this code using clang:

#include <iostream>
#include <type_traits>

enum class A {a,b,c};
enum B : short {x,y,z};

int main() {

  typedef std::underlying_type<A>::type A_under;   // int
  typedef std::underlying_type<B>::type B_under;   // short

  std::cout << std::boolalpha;
  std::cout << "typedefs of int:" << std::endl;

  std::cout << "A_under: " << std::is_same<int,A_under>::value << std::endl;
  std::cout << "B_under: " << std::is_same<int,B_under>::value << std::endl;

  return 0;
}

I get this error:

$ clang++ underlyingtype.cpp -std=c++11
underlyingtype.cpp:10:16: error: no type named 'underlying_type' in namespace 'std'
  typedef std::underlying_type<A>::type A_under;   // int

Any idea why this is happening?

Further information:

lashgar@fengdu:~/code$ clang++ --version
clang version 3.8.0 (http://llvm.org/git/clang.git 1ad799453a2e54cfded555a03fd58dbd102c5f62) (http://llvm.org/git/llvm.git af5ff60200812e518c72a022fb4c66b9a5f0116a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/lashgar/opt/llvm/bin

Here's a link to an online compiler with libstdc++ 4.6.4 that reproduces this error.

Just make sure to get the version of your Standard Library. libstdc++ 4.7 and higher or libc++ 3.0 and higher should work correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM