1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <optional> 11 12 // constexpr const T* optional<T>::operator->() const; 13 14 #ifdef _LIBCPP_DEBUG 15 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) 16 #endif 17 18 #include <experimental/optional> 19 #include <type_traits> 20 #include <cassert> 21 22 #if _LIBCPP_STD_VER > 11 23 24 using std::experimental::optional; 25 26 struct X 27 { testX28 constexpr int test() const {return 3;} 29 }; 30 31 struct Y 32 { testY33 int test() const {return 2;} 34 }; 35 36 struct Z 37 { operator &Z38 const Z* operator&() const {return this;} testZ39 constexpr int test() const {return 1;} 40 }; 41 42 #endif // _LIBCPP_STD_VER > 11 43 main()44int main() 45 { 46 #if _LIBCPP_STD_VER > 11 47 { 48 constexpr optional<X> opt(X{}); 49 static_assert(opt->test() == 3, ""); 50 } 51 { 52 constexpr optional<Y> opt(Y{}); 53 assert(opt->test() == 2); 54 } 55 { 56 constexpr optional<Z> opt(Z{}); 57 assert(opt->test() == 1); 58 } 59 #ifdef _LIBCPP_DEBUG 60 { 61 const optional<X> opt; 62 assert(opt->test() == 3); 63 assert(false); 64 } 65 #endif // _LIBCPP_DEBUG 66 #endif // _LIBCPP_STD_VER > 11 67 } 68