9#ifndef FORTRAN_COMMON_IDIOMS_H_
10#define FORTRAN_COMMON_IDIOMS_H_
17#error this is a C++ program
19#if __cplusplus < 201703L
20#error this is a C++17 program
22#if !__clang__ && defined __GNUC__ && __GNUC__ < 7
23#error g++ >= 7.2 is required
26#include "enum-class.h"
42struct is_trivially_copy_constructible<list<A>> : false_type {};
44struct is_trivially_copy_constructible<optional<list<A>>> : false_type {};
49using namespace std::literals::string_literals;
61template <
typename... LAMBDAS>
struct visitors : LAMBDAS... {
62 using LAMBDAS::operator()...;
65template <
typename... LAMBDAS>
visitors(LAMBDAS... x) ->
visitors<LAMBDAS...>;
68[[noreturn]]
void die(
const char *, ...);
70#define DIE(x) Fortran::common::die(x " at " __FILE__ "(%d)", __LINE__)
73#define CRASH_NO_CASE DIE("no case")
80#define SWITCH_COVERS_ALL_CASES
82#define SWITCH_COVERS_ALL_CASES default: CRASH_NO_CASE;
89#define CHECK(x) ((x) || (DIE("CHECK(" #x ") failed"), false))
94#define CHECK_MSG(x, y) ((x) || (DIE("CHECK(" #x ") failed: " #y), false))
103#define CLASS_TRAIT(T) \
104 namespace class_trait_ns_##T { \
105 template <typename A> std::true_type test(typename A::T *); \
106 template <typename A> std::false_type test(...); \
107 template <typename A> \
108 constexpr bool has_trait{decltype(test<A>(nullptr))::value}; \
109 template <typename A> constexpr bool trait_value() { \
110 if constexpr (has_trait<A>) { \
111 using U = typename A::T; \
118 template <typename A> constexpr bool T{class_trait_ns_##T::trait_value<A>()};
121#define DEREF(p) Fortran::common::Deref(p, __FILE__, __LINE__)
123template <
typename T>
constexpr T &Deref(T *p,
const char *file,
int line) {
125 Fortran::common::die(
"nullptr dereference at %s(%d)", file, line);
131constexpr T &Deref(
const std::unique_ptr<T> &p,
const char *file,
int line) {
133 Fortran::common::die(
"nullptr dereference at %s(%d)", file, line);
139template <
typename A> A Clone(
const A &x) {
return x; }
152template <
typename A,
typename... B>
153using IfNoLvalue = std::enable_if_t<(... && !std::is_lvalue_reference_v<B>), A>;
154template <
typename... RVREF>
using NoLvalue = IfNoLvalue<void, RVREF...>;
Definition: bit-population-count.h:20