/* * Souffle - A Datalog Compiler * Copyright (c) 2020, The Souffle Developers. All rights reserved * Licensed under the Universal Permissive License v 1.0 as shown at: * - https://opensource.org/licenses/UPL * - /licenses/SOUFFLE-UPL.txt */ /************************************************************************ * * @file Types.h * * @brief Shared type definitions * ***********************************************************************/ #pragma once #include #include #include #include namespace souffle { // TODO: replace with C++20 concepts template constexpr bool is_iterable_of = std::is_constructible_v()))>::value_type&>; // basically std::monostate, but doesn't require importing all of `` struct Unit {}; constexpr bool operator==(Unit, Unit) noexcept { return true; } constexpr bool operator<=(Unit, Unit) noexcept { return true; } constexpr bool operator>=(Unit, Unit) noexcept { return true; } constexpr bool operator!=(Unit, Unit) noexcept { return false; } constexpr bool operator<(Unit, Unit) noexcept { return false; } constexpr bool operator>(Unit, Unit) noexcept { return false; } template using Own = std::unique_ptr; template Own mk(Args&&... xs) { return std::make_unique(std::forward(xs)...); } template using VecOwn = std::vector>; /** * Copy the const qualifier of type T onto type U */ template using copy_const = std::conditional_t, const B, B>; namespace detail { template struct is_own_ptr_t : std::false_type {}; template struct is_own_ptr_t> : std::true_type {}; template struct is_range_impl : std::false_type {}; template struct is_range_impl()))>> : std::true_type {}; template struct is_associative : std::false_type {}; template struct is_associative> : std::true_type {}; template struct is_set : std::false_type {}; template struct is_set, std::void_t> : std::is_same {}; } // namespace detail template constexpr bool is_own_ptr = detail::is_own_ptr_t>::value; /** * A simple test to check if T is a range (i.e. has std::begin()) */ template struct is_range : detail::is_range_impl {}; template constexpr bool is_range_v = is_range::value; template constexpr bool is_remove_ref_const = std::is_const_v>; /** * Type identity, remove once we have C++20 */ template struct type_identity { using type = T; }; /** * Remove cv ref, remove once we have C++ 20 */ template using remove_cvref = std::remove_cv>; template using remove_cvref_t = typename remove_cvref::type; namespace detail { template struct is_pointer_like : std::is_pointer {}; template struct is_pointer_like> : std::true_type {}; } // namespace detail template constexpr bool is_pointer_like = detail::is_pointer_like>::value; // TODO: complete these or move to C++20 template constexpr bool is_associative = detail::is_associative::value; template constexpr bool is_set = detail::is_set::value; // Useful for `static_assert`ing in unhandled cases with `constexpr` static dispatching // Gives nicer error messages. (e.g. "failed due to req' unhandled_dispatch_type<...>") template constexpr bool unhandled_dispatch_type = !std::is_same_v; } // namespace souffle