| 1 | // Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 | // |
| 3 | // This file is part of the GNU ISO C++ Library. This library is free |
| 4 | // software; you can redistribute it and/or modify it under the |
| 5 | // terms of the GNU General Public License as published by the |
| 6 | // Free Software Foundation; either version 3, or (at your option) |
| 7 | // any later version. |
| 8 | // |
| 9 | // This library is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License along |
| 15 | // with this library; see the file COPYING3. If not see |
| 16 | // <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | // expensive: * [1-9] * * |
| 19 | #include "bits/main.h" |
| 20 | |
| 21 | template <class V> |
| 22 | struct call_generator |
| 23 | { |
| 24 | template <class F> |
| 25 | auto |
| 26 | operator()(const F& f) -> decltype(V(f)); |
| 27 | }; |
| 28 | |
| 29 | using schar = signed char; |
| 30 | using uchar = unsigned char; |
| 31 | using ullong = unsigned long long; |
| 32 | |
| 33 | template <typename V> |
| 34 | void |
| 35 | test() |
| 36 | { |
| 37 | using T = typename V::value_type; |
| 38 | V x([](int) { return T(1); }); |
| 39 | COMPARE(x, V(1)); |
| 40 | // unconditionally returns int from generator lambda |
| 41 | x = V([](int) { return 1; }); |
| 42 | COMPARE(x, V(1)); |
| 43 | x = V([](auto i) { return T(i); }); |
| 44 | COMPARE(x, V([](T i) { return i; })); |
| 45 | |
| 46 | VERIFY((// that int always works |
| 47 | sfinae_is_callable<int (&)(int)>(call_generator<V>()))); |
| 48 | COMPARE(sfinae_is_callable<schar (&)(int)>(call_generator<V>()), |
| 49 | std::is_signed<T>::value); |
| 50 | COMPARE(sfinae_is_callable<uchar (&)(int)>(call_generator<V>()), |
| 51 | !(std::is_signed_v<T> && sizeof(T) <= sizeof(uchar))); |
| 52 | COMPARE(sfinae_is_callable<float (&)(int)>(call_generator<V>()), |
| 53 | (std::is_floating_point<T>::value)); |
| 54 | |
| 55 | COMPARE(sfinae_is_callable<ullong (&)(int)>(call_generator<V>()), |
| 56 | std::__finite_max_v<T> >= std::__finite_max_v<ullong> |
| 57 | && std::__digits_v<T> >= std::__digits_v<ullong>); |
| 58 | } |