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"
41struct is_trivially_copy_constructible<list<A>> : false_type {};
43struct is_trivially_copy_constructible<optional<list<A>>> : false_type {};
48using namespace std::literals::string_literals;
60template <
typename... LAMBDAS>
struct visitors : LAMBDAS... {
61 using LAMBDAS::operator()...;
64template <
typename... LAMBDAS>
visitors(LAMBDAS... x) ->
visitors<LAMBDAS...>;
67[[noreturn]]
void die(
const char *, ...);
69#define DIE(x) Fortran::common::die(x " at " __FILE__ "(%d)", __LINE__)
72#define CRASH_NO_CASE DIE("no case")
79#define SWITCH_COVERS_ALL_CASES
81#define SWITCH_COVERS_ALL_CASES default: CRASH_NO_CASE;
88#define CHECK(x) ((x) || (DIE("CHECK(" #x ") failed"), false))
93#define CHECK_MSG(x, y) ((x) || (DIE("CHECK(" #x ") failed: " #y), false))
102#define CLASS_TRAIT(T) \
103 namespace class_trait_ns_##T { \
104 template <typename A> std::true_type test(typename A::T *); \
105 template <typename A> std::false_type test(...); \
106 template <typename A> \
107 constexpr bool has_trait{decltype(test<A>(nullptr))::value}; \
108 template <typename A> constexpr bool trait_value() { \
109 if constexpr (has_trait<A>) { \
110 using U = typename A::T; \
117 template <typename A> constexpr bool T{class_trait_ns_##T::trait_value<A>()};
120#define DEREF(p) Fortran::common::Deref(p, __FILE__, __LINE__)
122template <
typename T>
constexpr T &Deref(T *p,
const char *file,
int line) {
124 Fortran::common::die(
"nullptr dereference at %s(%d)", file, line);
130constexpr T &Deref(
const std::unique_ptr<T> &p,
const char *file,
int line) {
132 Fortran::common::die(
"nullptr dereference at %s(%d)", file, line);
138template <
typename A> A Clone(
const A &x) {
return x; }
151template <
typename A,
typename... B>
152using IfNoLvalue = std::enable_if_t<(... && !std::is_lvalue_reference_v<B>), A>;
153template <
typename... RVREF>
using NoLvalue = IfNoLvalue<void, RVREF...>;
Definition bit-population-count.h:20