boost_no_cxx11_thread_local.ipp 794 B

123456789101112131415161718192021222324252627282930313233343536
  1. // (C) Copyright John Maddock 2012.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/config for most recent version.
  6. // MACRO: BOOST_NO_CXX11_THREAD_LOCAL
  7. // TITLE: thread_local
  8. // DESCRIPTION: The compiler supports the thread_local storage specifier.
  9. #include <string>
  10. namespace boost_no_cxx11_thread_local{
  11. template <class T>
  12. int check_local(int n)
  13. {
  14. static thread_local T s(n, ' ');
  15. static thread_local int size = s.size();
  16. if(size != n)
  17. {
  18. s = T(n, ' ');
  19. size = n;
  20. }
  21. return size;
  22. }
  23. int test()
  24. {
  25. return check_local<std::string>(5) == 5 ? 0 : 1;
  26. }
  27. }