1// (C) Copyright Beman Dawes 2008 2 3// Use, modification and distribution are subject to the 4// Boost Software License, Version 1.0. (See accompanying file 5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 7// See http://www.boost.org/libs/config for more information. 8 9// MACRO: BOOST_NO_CXX11_CONSTEXPR 10// TITLE: C++0x constexpr unavailable 11// DESCRIPTION: The compiler does not support C++0x constexpr 12 13namespace boost_no_cxx11_constexpr { 14 15void quiet_warning(int){} 16 17constexpr int square(int x) { return x * x; } // from N2235 18 19// from 5.19: 20constexpr const int* addr(const int& ir) { return &ir; } 21static const int x = 5; 22constexpr const int* xp = addr(x); 23 24struct A 25{ 26 constexpr A(int i) : val(i) { } 27 constexpr operator int()const { return val; } 28 constexpr operator long()const { return 43; } 29private: 30 int val; 31}; 32 33template<int> struct X { }; 34 35constexpr const A a = 42; 36 37X<a> xx; // OK: unique conversion to int 38 39// virtual function 40struct B 41{ 42 virtual void vf() {} 43}; 44struct C : B 45{ 46 constexpr C() {} 47}; 48 49// aggregate initialization 50struct D 51{ 52 int val[2]; 53 constexpr D() : val() {} 54}; 55 56// virtual base 57struct E 58{ 59}; 60struct F : virtual E 61{ 62}; 63constexpr F& f(F& out) { return out; } 64 65namespace whatever{}; 66 67constexpr int factorial(int i) 68{ 69 typedef int value_type; 70 using namespace whatever; 71 return i <= 1 ? 1 : i * factorial(value_type(i-1)); 72} 73 74int test() 75{ 76 constexpr int i = square(5) + factorial(10); 77 quiet_warning(i); 78 79 switch (i) 80 { 81 case a: 82 break; 83 } 84 85 return 0; 86} 87 88} 89