boost_no_unified_init.ipp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (C) 2011 John Maddock
  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_UNIFIED_INITIALIZATION_SYNTAX
  7. // TITLE: C++0x unified initialization syntax unavailable
  8. // DESCRIPTION: The compiler does not support C++0x unified initialization syntax: see http://en.wikipedia.org/wiki/C%2B%2B0x#Uniform_initialization
  9. #include <string>
  10. namespace boost_no_cxx11_unified_initialization_syntax {
  11. struct BasicStruct
  12. {
  13. int x;
  14. double y;
  15. };
  16. struct AltStruct
  17. {
  18. public:
  19. AltStruct(int x, double y) : x_{x}, y_{y} {}
  20. int X() const { return x_; }
  21. double Y() const { return y_; }
  22. private:
  23. int x_;
  24. double y_;
  25. };
  26. struct IdString
  27. {
  28. std::string name;
  29. int identifier;
  30. bool operator == (const IdString& other)
  31. {
  32. return identifier == other.identifier && name == other.name;
  33. }
  34. };
  35. IdString get_string()
  36. {
  37. return {"SomeName", 4}; //Note the lack of explicit type.
  38. }
  39. int test()
  40. {
  41. BasicStruct var1{5, 3.2};
  42. AltStruct var2{2, 4.3};
  43. (void) var1;
  44. (void) var2;
  45. IdString id{"SomeName", 4};
  46. return id == get_string() ? 0 : 1;
  47. }
  48. }