| 1 | // Copyright (c) 2020-2024 Antony Polukhin |
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | // Detection of type loophole. |
| 7 | // Inspired by the blog post: http://alexpolt.github.io/type-loophole.html |
| 8 | |
| 9 | #include <type_traits> |
| 10 | |
| 11 | #if defined(_MSC_VER) && _MSC_VER <= 1916 |
| 12 | # error Compiler fails to do compile time computations for LoopHole. Fixed in later versions of the compiler |
| 13 | // Error: boost/pfr/detail/core14_loophole.hpp(98): error C3779: 'boost::pfr::detail::loophole': a function that returns 'auto' cannot be used before it is defined |
| 14 | #endif |
| 15 | |
| 16 | |
| 17 | template <unsigned> struct tag{}; |
| 18 | |
| 19 | template <class T, unsigned N> |
| 20 | struct loophole_t { |
| 21 | friend auto loophole(tag<N>) { return T{}; }; |
| 22 | }; |
| 23 | |
| 24 | auto loophole(tag<0>); |
| 25 | |
| 26 | int main() { |
| 27 | sizeof(loophole_t<unsigned, 0>); |
| 28 | static_assert( std::is_same<unsigned, decltype( loophole(tag<0>{}) ) >::value, "" ); |
| 29 | } |
| 30 | |