/usr/include/polymake/meta_function.h is in libpolymake-dev-common 3.2r2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | /* Copyright (c) 1997-2018
Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
http://www.polymake.org
This program 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 2, or (at your option) any
later version: http://www.gnu.org/licenses/gpl.txt.
This program 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.
--------------------------------------------------------------------------------
*/
#ifndef POLYMAKE_META_FUNCTION_H
#define POLYMAKE_META_FUNCTION_H
#include <type_traits>
namespace polymake {
template <bool TValue>
using bool_constant = std::integral_constant<bool, TValue>;
template <int TValue>
using int_constant = std::integral_constant<int, TValue>;
template <char TValue>
using char_constant = std::integral_constant<char, TValue>;
/// Choose the type occurring in the first satisifed clause.
/// Every clause but the last one must be an instance of std::enable_if.
/// The last clause may be a single type with serves as an 'otherwise' case.
/// If there is no such fallback, the resulting type is undefined.
template <typename... TClauses>
struct mselect;
template <typename T>
struct mselect<std::enable_if<true, T>> {
typedef T type;
};
template <typename T, typename T2, typename... TTail>
struct mselect<std::enable_if<true, T>, T2, TTail...> {
typedef T type;
};
template <typename T, typename T2, typename... TTail>
struct mselect<std::enable_if<false, T>, T2, TTail...>
: mselect<T2, TTail...> {};
template <typename T>
struct mselect<std::enable_if<false, T>> {};
template <typename T>
struct mselect<T> {
typedef T type;
};
/// Operation on a pair of types: selects the first one
template <typename T1, typename T2>
struct mproject1st {
typedef T1 type;
};
/// Operation on a pair of types: selects the first one unless it is void
template <typename T1, typename T2>
struct mprefer1st {
typedef T1 type;
};
template <typename T2>
struct mprefer1st<void, T2> {
typedef T2 type;
};
/// Operation on a pair of types: selects the second one
template <typename T1, typename T2>
struct mproject2nd {
typedef T2 type;
};
/// Operation on a pair of types: selects the second one unless it is void
template <typename T1, typename T2>
struct mprefer2nd {
typedef T2 type;
};
template <typename T1>
struct mprefer2nd<T1, void> {
typedef T1 type;
};
/// container for arbitrary many types
template <typename... T>
struct mlist {};
/// Check whether a type is an instance of a given class template
template <typename T, template <typename...> class Template>
struct is_instance_of
: std::false_type {
typedef mlist<> params;
};
template <typename... T, template <typename...> class Template>
struct is_instance_of<Template<T...>, Template>
: std::true_type {
typedef mlist<T...> params;
};
/// wrapper for a meta-function
/// allows to pass meta-functions as elements of (tagged) meta-lists
template <template <typename...> class TFunction>
struct meta_function {
template <typename T> struct apply;
template <typename... T>
struct apply<mlist<T...>>
: TFunction<T...> {};
};
/// Safely evaluate a meta-function.
/// If its result is undefined, deliver the fallback value.
template <typename TFunction, typename TFallback, typename TDefined=void>
struct mevaluate {
typedef TFallback type;
};
template <typename TFunction, typename TFallback>
struct mevaluate<TFunction, TFallback, typename mproject2nd<typename TFunction::type, void>::type>
: TFunction {};
}
#endif // POLYMAKE_META_FUNCTION_H
// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End:
|