summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/experimental/simd/tests/generator.cc
blob: 001625cfd26b7fa8b100a22db08683ababfc41a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (C) 2020-2023 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// expensive: * [1-9] * *
#include "bits/main.h"

template <class V>
  struct call_generator
  {
    template <class F>
      auto
      operator()(const F& f) -> decltype(V(f));
  };

using schar = signed char;
using uchar = unsigned char;
using ullong = unsigned long long;

template <typename V>
  void
  test()
  {
    using T = typename V::value_type;
    V x([](int) { return T(1); });
    COMPARE(x, V(1));
    // unconditionally returns int from generator lambda
    x = V([](int) { return 1; });
    COMPARE(x, V(1));
    x = V([](auto i) { return T(i); });
    COMPARE(x, V([](T i) { return i; }));

    VERIFY((// that int always works
	sfinae_is_callable<int (&)(int)>(call_generator<V>())));
    COMPARE(sfinae_is_callable<schar (&)(int)>(call_generator<V>()),
	    std::is_signed<T>::value);
    COMPARE(sfinae_is_callable<uchar (&)(int)>(call_generator<V>()),
	    !(std::is_signed_v<T> && sizeof(T) <= sizeof(uchar)));
    COMPARE(sfinae_is_callable<float (&)(int)>(call_generator<V>()),
	    (std::is_floating_point<T>::value));

    COMPARE(sfinae_is_callable<ullong (&)(int)>(call_generator<V>()),
      std::__finite_max_v<T> >= std::__finite_max_v<ullong>
      && std::__digits_v<T> >= std::__digits_v<ullong>);
  }