1 #include "config.h" 2 3 #include <type_traits> 4 #include <utility> 5 #include <vector> 6 7 #include <dune/common/typetraits.hh> 8 #include <dune/common/typeutilities.hh> 9 10 template<class T> doAutoCopy(T && v)11constexpr auto doAutoCopy(T &&v) 12 { 13 return Dune::autoCopy(std::forward<T>(v)); 14 } 15 16 // an example expression object that evaluates to int(0) 17 struct ZeroExpr { operator intZeroExpr18 constexpr operator int() const volatile { return 0; } 19 }; 20 21 namespace Dune { 22 template<> 23 struct AutonomousValueType<ZeroExpr> { using type = int; }; 24 25 // doAutoCopy should not pick up this overload 26 constexpr auto autoCopy(ZeroExpr) = delete; 27 } // namespace Dune 28 main()29int main() 30 { 31 32 { 33 std::vector<bool> v{true}; 34 auto ref = v[0]; 35 static_assert(!std::is_same<decltype(ref), bool>::value, 36 "sanity check failed"); 37 auto val = Dune::autoCopy(v[0]); 38 static_assert(std::is_same<decltype(val), bool>::value, 39 "vector<bool>::reference not resolved"); 40 } 41 42 { 43 constexpr ZeroExpr zexpr{}; 44 auto val = doAutoCopy(zexpr); 45 static_assert(std::is_same<decltype(val), int>::value, 46 "Custom type was not resolved"); 47 48 static_assert(doAutoCopy(zexpr) == 0, 49 "Resolution is not constexpr"); 50 } 51 52 } 53