File: 4.cc

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (59 lines) | stat: -rw-r--r-- 2,004 bytes parent folder | download
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
59
// { dg-do compile { target c++23 } }
// { dg-add-options no_pch }

#include <functional>

#ifndef __cpp_lib_invoke_r
# error Feature-test macro for invoke_r is missing in <functional>
#elif __cpp_lib_invoke_r < 202106L
# error Feature-test macro for invoke_r has the wrong value in <functional>
#endif

constexpr int sq(int i) { return i * i; }

template<typename Val, typename Expected>
constexpr bool chk(Val&& val, Expected&& exp)
{
  return std::is_same_v<Val, Expected> && val == exp;
}

void
test01()
{
  static_assert( chk( std::invoke(sq, 2), 4 ) );
  static_assert( chk( std::invoke_r<int>(sq, 3), 9 ) );
  static_assert( chk( std::invoke_r<char>(sq, 4), '\x10' ) );
}

struct abstract {
  virtual ~abstract() = 0;
  void operator()() noexcept;
};

static_assert( noexcept(std::invoke(std::declval<abstract>())),
    "It should be possible to use abstract types with INVOKE" );

static_assert( noexcept(std::invoke_r<void>(std::declval<abstract>())),
    "It should be possible to use abstract types with INVOKE<R>" );

struct F {
  void operator()() &;
  void operator()() && noexcept;
  int operator()(int);
  double* operator()(int, int) noexcept;
};
struct D { D(void*); };

static_assert( !noexcept(std::invoke(std::declval<F&>())) );
static_assert( noexcept(std::invoke(std::declval<F>())) );
static_assert( !noexcept(std::invoke(std::declval<F>(), 1)) );
static_assert( noexcept(std::invoke(std::declval<F>(), 1, 2)) );

static_assert( !noexcept(std::invoke_r<void>(std::declval<F&>())) );
static_assert( noexcept(std::invoke_r<void>(std::declval<F>())) );
static_assert( !noexcept(std::invoke_r<int>(std::declval<F>(), 1)) );
static_assert( !noexcept(std::invoke_r<void>(std::declval<F>(), 1)) );
static_assert( !noexcept(std::invoke_r<long>(std::declval<F>(), 1)) );
static_assert( noexcept(std::invoke_r<void>(std::declval<F>(), 1, 2)) );
static_assert( noexcept(std::invoke_r<void*>(std::declval<F>(), 1, 2)) );
static_assert( !noexcept(std::invoke_r<D>(std::declval<F>(), 1, 2)) );