2018-09-28 14:55:09 +08:00
|
|
|
// sol3
|
2017-12-20 17:58:32 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
// The MIT License (MIT)
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2018-02-20 10:15:26 +08:00
|
|
|
// Copyright (c) 2013-2018 Rapptz, ThePhD and contributors
|
2017-02-17 18:46:39 +08:00
|
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
// this software and associated documentation files (the "Software"), to deal in
|
|
|
|
// the Software without restriction, including without limitation the rights to
|
|
|
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
// the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
// subject to the following conditions:
|
|
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
#ifndef SOL_TRAITS_HPP
|
|
|
|
#define SOL_TRAITS_HPP
|
|
|
|
|
|
|
|
#include "tuple.hpp"
|
|
|
|
#include "bind_traits.hpp"
|
2018-02-03 14:29:06 +08:00
|
|
|
#include "string_view.hpp"
|
2017-11-17 20:07:56 +08:00
|
|
|
|
2017-02-17 18:46:39 +08:00
|
|
|
#include <type_traits>
|
2017-11-17 20:07:56 +08:00
|
|
|
#include <cstdint>
|
2017-02-17 18:46:39 +08:00
|
|
|
#include <memory>
|
|
|
|
#include <functional>
|
2018-07-30 01:11:21 +08:00
|
|
|
#include <array>
|
2017-05-29 22:32:37 +08:00
|
|
|
#include <iterator>
|
2017-08-11 15:24:17 +08:00
|
|
|
#include <iosfwd>
|
2018-02-03 14:29:06 +08:00
|
|
|
|
2017-02-17 18:46:39 +08:00
|
|
|
|
|
|
|
namespace sol {
|
|
|
|
namespace meta {
|
2018-12-20 12:17:15 +08:00
|
|
|
template <std::size_t I>
|
|
|
|
using index_value = std::integral_constant<std::size_t, I>;
|
|
|
|
|
|
|
|
template <bool>
|
|
|
|
struct conditional {
|
|
|
|
template <typename T, typename U>
|
|
|
|
using type = T;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct conditional<false> {
|
|
|
|
template <typename T, typename U>
|
|
|
|
using type = U;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <bool B, typename T, typename U>
|
|
|
|
using conditional_t = typename conditional<B>::template type<T, U>;
|
|
|
|
|
|
|
|
using sfinae_yes_t = std::true_type;
|
|
|
|
using sfinae_no_t = std::false_type;
|
2018-06-16 01:19:09 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2018-12-20 12:17:15 +08:00
|
|
|
struct identity {
|
|
|
|
typedef T type;
|
|
|
|
};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
using identity_t = typename identity<T>::type;
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename... Args>
|
|
|
|
struct is_tuple : std::false_type {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename... Args>
|
|
|
|
struct is_tuple<std::tuple<Args...>> : std::true_type {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct is_builtin_type : std::integral_constant<bool, std::is_arithmetic<T>::value || std::is_pointer<T>::value || std::is_array<T>::value> {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct unwrapped {
|
|
|
|
typedef T type;
|
|
|
|
};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct unwrapped<std::reference_wrapper<T>> {
|
|
|
|
typedef T type;
|
|
|
|
};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
using unwrapped_t = typename unwrapped<T>::type;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct unwrap_unqualified : unwrapped<unqualified_t<T>> {};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
using unwrap_unqualified_t = typename unwrap_unqualified<T>::type;
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct remove_member_pointer;
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename R, typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct remove_member_pointer<R T::*> {
|
|
|
|
typedef R type;
|
|
|
|
};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename R, typename T>
|
|
|
|
struct remove_member_pointer<R T::*const> {
|
2017-02-17 18:46:39 +08:00
|
|
|
typedef R type;
|
|
|
|
};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
using remove_member_pointer_t = remove_member_pointer<T>;
|
|
|
|
|
2018-03-02 11:08:27 +08:00
|
|
|
namespace meta_detail {
|
|
|
|
template <typename T, template <typename...> class Templ>
|
|
|
|
struct is_specialization_of : std::false_type {};
|
|
|
|
template <typename... T, template <typename...> class Templ>
|
|
|
|
struct is_specialization_of<Templ<T...>, Templ> : std::true_type {};
|
2018-09-28 13:27:38 +08:00
|
|
|
} // namespace meta_detail
|
2018-03-02 11:08:27 +08:00
|
|
|
|
|
|
|
template <typename T, template <typename...> class Templ>
|
|
|
|
using is_specialization_of = meta_detail::is_specialization_of<std::remove_cv_t<T>, Templ>;
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2018-12-20 12:17:15 +08:00
|
|
|
template <typename T, template <typename...> class Templ>
|
|
|
|
constexpr bool is_specialization_of_v = is_specialization_of<std::remove_cv_t<T>, Templ>::value;
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <class T, class...>
|
|
|
|
struct all_same : std::true_type {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <class T, class U, class... Args>
|
|
|
|
struct all_same<T, U, Args...> : std::integral_constant<bool, std::is_same<T, U>::value && all_same<T, Args...>::value> {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <class T, class...>
|
|
|
|
struct any_same : std::false_type {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <class T, class U, class... Args>
|
|
|
|
struct any_same<T, U, Args...> : std::integral_constant<bool, std::is_same<T, U>::value || any_same<T, Args...>::value> {};
|
2017-08-06 07:20:28 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <bool B>
|
2017-08-06 07:20:28 +08:00
|
|
|
using boolean = std::integral_constant<bool, B>;
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
using invoke_t = typename T::type;
|
|
|
|
|
2017-08-06 07:20:28 +08:00
|
|
|
template <typename T>
|
|
|
|
using invoke_b = boolean<T::value>;
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
using neg = boolean<!T::value>;
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename Condition, typename Then, typename Else>
|
2018-12-20 12:17:15 +08:00
|
|
|
using condition = conditional_t<Condition::value, Then, Else>;
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename... Args>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct all : boolean<true> {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T, typename... Args>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct all<T, Args...> : condition<T, all<Args...>, boolean<false>> {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename... Args>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct any : boolean<false> {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T, typename... Args>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct any<T, Args...> : condition<T, boolean<true>, any<Args...>> {};
|
|
|
|
|
2018-12-20 12:17:15 +08:00
|
|
|
enum class enable_t { _ };
|
2017-02-17 18:46:39 +08:00
|
|
|
|
|
|
|
constexpr const auto enabler = enable_t::_;
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <bool value, typename T = void>
|
2017-02-17 18:46:39 +08:00
|
|
|
using disable_if_t = std::enable_if_t<!value, T>;
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename... Args>
|
2017-02-17 18:46:39 +08:00
|
|
|
using enable = std::enable_if_t<all<Args...>::value, enable_t>;
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename... Args>
|
2018-03-02 11:08:27 +08:00
|
|
|
using disable = std::enable_if_t<neg<all<Args...>>::value, enable_t>;
|
2017-09-12 04:12:23 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename... Args>
|
2018-03-02 11:08:27 +08:00
|
|
|
using enable_any = std::enable_if_t<any<Args...>::value, enable_t>;
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename... Args>
|
2017-02-17 18:46:39 +08:00
|
|
|
using disable_any = std::enable_if_t<neg<any<Args...>>::value, enable_t>;
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename V, typename... Vs>
|
|
|
|
struct find_in_pack_v : boolean<false> {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename V, typename Vs1, typename... Vs>
|
|
|
|
struct find_in_pack_v<V, Vs1, Vs...> : any<boolean<(V::value == Vs1::value)>, find_in_pack_v<V, Vs...>> {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
|
|
|
namespace meta_detail {
|
2017-09-13 14:46:56 +08:00
|
|
|
template <std::size_t I, typename T, typename... Args>
|
|
|
|
struct index_in_pack : std::integral_constant<std::size_t, SIZE_MAX> {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <std::size_t I, typename T, typename T1, typename... Args>
|
2018-12-20 12:17:15 +08:00
|
|
|
struct index_in_pack<I, T, T1, Args...>
|
|
|
|
: conditional_t<std::is_same<T, T1>::value, std::integral_constant<std::ptrdiff_t, I>, index_in_pack<I + 1, T, Args...>> {};
|
2017-09-13 14:46:56 +08:00
|
|
|
} // namespace meta_detail
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T, typename... Args>
|
|
|
|
struct index_in_pack : meta_detail::index_in_pack<0, T, Args...> {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T, typename List>
|
|
|
|
struct index_in : meta_detail::index_in_pack<0, T, List> {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T, typename... Args>
|
|
|
|
struct index_in<T, types<Args...>> : meta_detail::index_in_pack<0, T, Args...> {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <std::size_t I, typename... Args>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct at_in_pack {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <std::size_t I, typename... Args>
|
2017-02-17 18:46:39 +08:00
|
|
|
using at_in_pack_t = typename at_in_pack<I, Args...>::type;
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <std::size_t I, typename Arg, typename... Args>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct at_in_pack<I, Arg, Args...> : std::conditional<I == 0, Arg, at_in_pack_t<I - 1, Args...>> {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename Arg, typename... Args>
|
2018-12-20 12:17:15 +08:00
|
|
|
struct at_in_pack<0, Arg, Args...> {
|
|
|
|
typedef Arg type;
|
|
|
|
};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
|
|
|
namespace meta_detail {
|
2017-09-13 14:46:56 +08:00
|
|
|
template <std::size_t Limit, std::size_t I, template <typename...> class Pred, typename... Ts>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct count_for_pack : std::integral_constant<std::size_t, 0> {};
|
2017-09-13 14:46:56 +08:00
|
|
|
template <std::size_t Limit, std::size_t I, template <typename...> class Pred, typename T, typename... Ts>
|
2018-12-20 12:17:15 +08:00
|
|
|
struct count_for_pack<Limit, I, Pred, T, Ts...> : conditional_t<sizeof...(Ts)
|
|
|
|
== 0
|
|
|
|
|| Limit<2, std::integral_constant<std::size_t, I + static_cast<std::size_t>(Limit != 0 && Pred<T>::value)>,
|
|
|
|
count_for_pack<Limit - 1, I + static_cast<std::size_t>(Pred<T>::value), Pred, Ts...>> {};
|
2017-09-13 14:46:56 +08:00
|
|
|
template <std::size_t I, template <typename...> class Pred, typename... Ts>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct count_2_for_pack : std::integral_constant<std::size_t, 0> {};
|
2017-09-13 14:46:56 +08:00
|
|
|
template <std::size_t I, template <typename...> class Pred, typename T, typename U, typename... Ts>
|
2018-12-20 12:17:15 +08:00
|
|
|
struct count_2_for_pack<I, Pred, T, U, Ts...>
|
|
|
|
: conditional_t<sizeof...(Ts) == 0, std::integral_constant<std::size_t, I + static_cast<std::size_t>(Pred<T>::value)>,
|
|
|
|
count_2_for_pack<I + static_cast<std::size_t>(Pred<T>::value), Pred, Ts...>> {};
|
2017-09-13 14:46:56 +08:00
|
|
|
} // namespace meta_detail
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <template <typename...> class Pred, typename... Ts>
|
|
|
|
struct count_for_pack : meta_detail::count_for_pack<sizeof...(Ts), 0, Pred, Ts...> {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <template <typename...> class Pred, typename List>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct count_for;
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <template <typename...> class Pred, typename... Args>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct count_for<Pred, types<Args...>> : count_for_pack<Pred, Args...> {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <std::size_t Limit, template <typename...> class Pred, typename... Ts>
|
|
|
|
struct count_for_to_pack : meta_detail::count_for_pack<Limit, 0, Pred, Ts...> {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <template <typename...> class Pred, typename... Ts>
|
|
|
|
struct count_2_for_pack : meta_detail::count_2_for_pack<0, Pred, Ts...> {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename... Args>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct return_type {
|
|
|
|
typedef std::tuple<Args...> type;
|
|
|
|
};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct return_type<T> {
|
|
|
|
typedef T type;
|
|
|
|
};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct return_type<> {
|
|
|
|
typedef void type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
using return_type_t = typename return_type<Args...>::type;
|
|
|
|
|
|
|
|
namespace meta_detail {
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename>
|
|
|
|
struct always_true : std::true_type {};
|
2017-02-17 18:46:39 +08:00
|
|
|
struct is_invokable_tester {
|
|
|
|
template <typename Fun, typename... Args>
|
2017-12-20 17:58:32 +08:00
|
|
|
static always_true<decltype(std::declval<Fun>()(std::declval<Args>()...))> test(int);
|
2017-02-17 18:46:39 +08:00
|
|
|
template <typename...>
|
2017-12-20 17:58:32 +08:00
|
|
|
static std::false_type test(...);
|
2017-02-17 18:46:39 +08:00
|
|
|
};
|
2017-09-13 14:46:56 +08:00
|
|
|
} // namespace meta_detail
|
2017-02-17 18:46:39 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct is_invokable;
|
|
|
|
template <typename Fun, typename... Args>
|
|
|
|
struct is_invokable<Fun(Args...)> : decltype(meta_detail::is_invokable_tester::test<Fun, Args...>(0)) {};
|
|
|
|
|
|
|
|
namespace meta_detail {
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T, typename = void>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct is_callable : std::is_function<std::remove_pointer_t<T>> {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2018-12-20 12:17:15 +08:00
|
|
|
struct is_callable<T,
|
|
|
|
std::enable_if_t<std::is_final<unqualified_t<T>>::value && std::is_class<unqualified_t<T>>::value
|
|
|
|
&& std::is_same<decltype(void(&T::operator())), void>::value>> {};
|
2017-10-27 00:53:52 +08:00
|
|
|
|
|
|
|
template <typename T>
|
2018-12-20 12:17:15 +08:00
|
|
|
struct is_callable<T,
|
|
|
|
std::enable_if_t<!std::is_final<unqualified_t<T>>::value && std::is_class<unqualified_t<T>>::value
|
|
|
|
&& std::is_destructible<unqualified_t<T>>::value>> {
|
2017-09-13 14:46:56 +08:00
|
|
|
struct F {
|
|
|
|
void operator()();
|
|
|
|
};
|
|
|
|
struct Derived : T, F {};
|
|
|
|
template <typename U, U>
|
|
|
|
struct Check;
|
2017-08-25 02:39:02 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename V>
|
2018-09-28 13:27:38 +08:00
|
|
|
static sfinae_no_t test(Check<void (F::*)(), &V::operator()>*);
|
2017-08-25 02:39:02 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename>
|
2018-09-28 13:27:38 +08:00
|
|
|
static sfinae_yes_t test(...);
|
2017-08-25 02:39:02 +08:00
|
|
|
|
2018-12-20 12:17:15 +08:00
|
|
|
static constexpr bool value = std::is_same_v<decltype(test<Derived>(0)), sfinae_yes_t>;
|
2017-08-25 02:39:02 +08:00
|
|
|
};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2018-12-20 12:17:15 +08:00
|
|
|
struct is_callable<T,
|
|
|
|
std::enable_if_t<!std::is_final<unqualified_t<T>>::value && std::is_class<unqualified_t<T>>::value
|
|
|
|
&& !std::is_destructible<unqualified_t<T>>::value>> {
|
2017-09-13 14:46:56 +08:00
|
|
|
struct F {
|
|
|
|
void operator()();
|
|
|
|
};
|
|
|
|
struct Derived : T, F {
|
|
|
|
~Derived() = delete;
|
|
|
|
};
|
|
|
|
template <typename U, U>
|
|
|
|
struct Check;
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename V>
|
2018-09-28 13:27:38 +08:00
|
|
|
static sfinae_no_t test(Check<void (F::*)(), &V::operator()>*);
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename>
|
2018-09-28 13:27:38 +08:00
|
|
|
static sfinae_yes_t test(...);
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2018-12-20 12:17:15 +08:00
|
|
|
static constexpr bool value = std::is_same_v<decltype(test<Derived>(0)), sfinae_yes_t>;
|
2017-02-17 18:46:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct has_begin_end_impl {
|
2018-12-20 12:17:15 +08:00
|
|
|
template <typename T, typename U = unqualified_t<T>, typename B = decltype(std::declval<U&>().begin()),
|
|
|
|
typename E = decltype(std::declval<U&>().end())>
|
2017-09-13 14:46:56 +08:00
|
|
|
static std::true_type test(int);
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename...>
|
2017-02-17 18:46:39 +08:00
|
|
|
static std::false_type test(...);
|
|
|
|
};
|
|
|
|
|
2017-06-24 06:07:24 +08:00
|
|
|
struct has_key_type_impl {
|
2018-12-20 12:17:15 +08:00
|
|
|
template <typename T, typename U = unqualified_t<T>, typename V = typename U::key_type>
|
2017-09-13 14:46:56 +08:00
|
|
|
static std::true_type test(int);
|
2017-06-24 06:07:24 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename...>
|
2017-06-24 06:07:24 +08:00
|
|
|
static std::false_type test(...);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct has_mapped_type_impl {
|
2018-12-20 12:17:15 +08:00
|
|
|
template <typename T, typename U = unqualified_t<T>, typename V = typename U::mapped_type>
|
2017-09-13 14:46:56 +08:00
|
|
|
static std::true_type test(int);
|
2017-06-24 06:07:24 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename...>
|
2017-06-24 06:07:24 +08:00
|
|
|
static std::false_type test(...);
|
|
|
|
};
|
|
|
|
|
2017-07-10 00:00:57 +08:00
|
|
|
struct has_value_type_impl {
|
2018-12-20 12:17:15 +08:00
|
|
|
template <typename T, typename U = unqualified_t<T>, typename V = typename U::value_type>
|
2017-09-13 14:46:56 +08:00
|
|
|
static std::true_type test(int);
|
2017-07-10 00:00:57 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename...>
|
2017-07-10 00:00:57 +08:00
|
|
|
static std::false_type test(...);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct has_iterator_impl {
|
2018-12-20 12:17:15 +08:00
|
|
|
template <typename T, typename U = unqualified_t<T>, typename V = typename U::iterator>
|
2017-09-13 14:46:56 +08:00
|
|
|
static std::true_type test(int);
|
2017-07-10 00:00:57 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename...>
|
2017-07-10 00:00:57 +08:00
|
|
|
static std::false_type test(...);
|
|
|
|
};
|
|
|
|
|
2017-02-17 18:46:39 +08:00
|
|
|
struct has_key_value_pair_impl {
|
2018-12-20 12:17:15 +08:00
|
|
|
template <typename T, typename U = unqualified_t<T>, typename V = typename U::value_type, typename F = decltype(std::declval<V&>().first),
|
|
|
|
typename S = decltype(std::declval<V&>().second)>
|
2017-09-13 14:46:56 +08:00
|
|
|
static std::true_type test(int);
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename...>
|
2017-02-17 18:46:39 +08:00
|
|
|
static std::false_type test(...);
|
|
|
|
};
|
|
|
|
|
2017-08-06 07:20:28 +08:00
|
|
|
template <typename T>
|
|
|
|
struct has_push_back_test {
|
|
|
|
private:
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename C>
|
2018-09-28 13:27:38 +08:00
|
|
|
static sfinae_yes_t test(decltype(std::declval<C>().push_back(std::declval<std::add_rvalue_reference_t<typename C::value_type>>()))*);
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename C>
|
2018-06-16 01:19:09 +08:00
|
|
|
static sfinae_no_t test(...);
|
2017-08-06 07:20:28 +08:00
|
|
|
|
|
|
|
public:
|
2018-12-20 12:17:15 +08:00
|
|
|
static constexpr bool value = std::is_same_v<decltype(test<T>(0)), sfinae_yes_t>;
|
2017-08-06 07:20:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct has_insert_test {
|
|
|
|
private:
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename C>
|
2018-12-20 12:17:15 +08:00
|
|
|
static sfinae_yes_t test(decltype(std::declval<C>().insert(std::declval<std::add_rvalue_reference_t<typename C::const_iterator>>(),
|
|
|
|
std::declval<std::add_rvalue_reference_t<typename C::value_type>>()))*);
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename C>
|
2018-06-16 01:19:09 +08:00
|
|
|
static sfinae_no_t test(...);
|
2017-08-06 07:20:28 +08:00
|
|
|
|
|
|
|
public:
|
2018-12-20 12:17:15 +08:00
|
|
|
static constexpr bool value = std::is_same_v<decltype(test<T>(0)), sfinae_yes_t>;
|
2017-08-06 07:20:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct has_insert_after_test {
|
|
|
|
private:
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename C>
|
2018-12-20 12:17:15 +08:00
|
|
|
static sfinae_yes_t test(decltype(std::declval<C>().insert_after(std::declval<std::add_rvalue_reference_t<typename C::const_iterator>>(),
|
|
|
|
std::declval<std::add_rvalue_reference_t<typename C::value_type>>()))*);
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename C>
|
2018-06-16 01:19:09 +08:00
|
|
|
static sfinae_no_t test(...);
|
2017-08-06 07:20:28 +08:00
|
|
|
|
|
|
|
public:
|
2018-12-20 12:17:15 +08:00
|
|
|
static constexpr bool value = std::is_same_v<decltype(test<T>(0)), sfinae_yes_t>;
|
2017-08-06 07:20:28 +08:00
|
|
|
};
|
|
|
|
|
2017-08-11 15:24:17 +08:00
|
|
|
template <typename T>
|
|
|
|
struct has_size_test {
|
|
|
|
private:
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename C>
|
2018-06-16 01:19:09 +08:00
|
|
|
static sfinae_yes_t test(decltype(std::declval<C>().size())*);
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename C>
|
2018-06-16 01:19:09 +08:00
|
|
|
static sfinae_no_t test(...);
|
2017-08-11 15:24:17 +08:00
|
|
|
|
|
|
|
public:
|
2018-12-20 12:17:15 +08:00
|
|
|
static constexpr bool value = std::is_same_v<decltype(test<T>(0)), sfinae_yes_t>;
|
2018-06-16 01:19:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
struct has_max_size_test {
|
|
|
|
private:
|
|
|
|
template <typename C>
|
|
|
|
static sfinae_yes_t test(decltype(std::declval<C>().max_size())*);
|
|
|
|
template <typename C>
|
|
|
|
static sfinae_no_t test(...);
|
|
|
|
|
|
|
|
public:
|
2018-12-20 12:17:15 +08:00
|
|
|
static constexpr bool value = std::is_same_v<decltype(test<T>(0)), sfinae_yes_t>;
|
2017-08-11 15:24:17 +08:00
|
|
|
};
|
|
|
|
|
2017-08-22 03:25:43 +08:00
|
|
|
template <typename T>
|
|
|
|
struct has_to_string_test {
|
|
|
|
private:
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename C>
|
2018-06-16 01:19:09 +08:00
|
|
|
static sfinae_yes_t test(decltype(std::declval<C>().to_string())*);
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename C>
|
2018-06-16 01:19:09 +08:00
|
|
|
static sfinae_no_t test(...);
|
2017-08-22 03:25:43 +08:00
|
|
|
|
|
|
|
public:
|
2018-12-20 12:17:15 +08:00
|
|
|
static constexpr bool value = std::is_same_v<decltype(test<T>(0)), sfinae_yes_t>;
|
2017-08-22 03:25:43 +08:00
|
|
|
};
|
2018-12-20 12:17:15 +08:00
|
|
|
|
2017-08-22 03:25:43 +08:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER <= 1910
|
|
|
|
template <typename T, typename U, typename = decltype(std::declval<T&>() < std::declval<U&>())>
|
|
|
|
std::true_type supports_op_less_test(std::reference_wrapper<T>, std::reference_wrapper<U>);
|
|
|
|
std::false_type supports_op_less_test(...);
|
|
|
|
template <typename T, typename U, typename = decltype(std::declval<T&>() == std::declval<U&>())>
|
|
|
|
std::true_type supports_op_equal_test(std::reference_wrapper<T>, std::reference_wrapper<U>);
|
|
|
|
std::false_type supports_op_equal_test(...);
|
|
|
|
template <typename T, typename U, typename = decltype(std::declval<T&>() <= std::declval<U&>())>
|
|
|
|
std::true_type supports_op_less_equal_test(std::reference_wrapper<T>, std::reference_wrapper<U>);
|
|
|
|
std::false_type supports_op_less_equal_test(...);
|
|
|
|
template <typename T, typename OS, typename = decltype(std::declval<OS&>() << std::declval<T&>())>
|
|
|
|
std::true_type supports_ostream_op(std::reference_wrapper<T>, std::reference_wrapper<OS>);
|
|
|
|
std::false_type supports_ostream_op(...);
|
|
|
|
template <typename T, typename = decltype(to_string(std::declval<T&>()))>
|
|
|
|
std::true_type supports_adl_to_string(std::reference_wrapper<T>);
|
|
|
|
std::false_type supports_adl_to_string(...);
|
|
|
|
#else
|
2017-08-06 07:20:28 +08:00
|
|
|
template <typename T, typename U, typename = decltype(std::declval<T&>() < std::declval<U&>())>
|
|
|
|
std::true_type supports_op_less_test(const T&, const U&);
|
2017-02-17 18:46:39 +08:00
|
|
|
std::false_type supports_op_less_test(...);
|
2017-08-06 07:20:28 +08:00
|
|
|
template <typename T, typename U, typename = decltype(std::declval<T&>() == std::declval<U&>())>
|
|
|
|
std::true_type supports_op_equal_test(const T&, const U&);
|
2017-02-17 18:46:39 +08:00
|
|
|
std::false_type supports_op_equal_test(...);
|
2017-08-06 07:20:28 +08:00
|
|
|
template <typename T, typename U, typename = decltype(std::declval<T&>() <= std::declval<U&>())>
|
|
|
|
std::true_type supports_op_less_equal_test(const T&, const U&);
|
2017-02-17 18:46:39 +08:00
|
|
|
std::false_type supports_op_less_equal_test(...);
|
2017-08-11 15:24:17 +08:00
|
|
|
template <typename T, typename OS, typename = decltype(std::declval<OS&>() << std::declval<T&>())>
|
|
|
|
std::true_type supports_ostream_op(const T&, const OS&);
|
|
|
|
std::false_type supports_ostream_op(...);
|
2017-08-22 03:25:43 +08:00
|
|
|
template <typename T, typename = decltype(to_string(std::declval<T&>()))>
|
|
|
|
std::true_type supports_adl_to_string(const T&);
|
|
|
|
std::false_type supports_adl_to_string(...);
|
|
|
|
#endif
|
2017-12-20 17:58:32 +08:00
|
|
|
|
|
|
|
template <typename T, bool b>
|
|
|
|
struct is_matched_lookup_impl : std::false_type {};
|
|
|
|
template <typename T>
|
|
|
|
struct is_matched_lookup_impl<T, true> : std::is_same<typename T::key_type, typename T::value_type> {};
|
2017-09-13 14:46:56 +08:00
|
|
|
} // namespace meta_detail
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-08-22 03:25:43 +08:00
|
|
|
#if defined(_MSC_VER) && _MSC_VER <= 1910
|
|
|
|
template <typename T, typename U = T>
|
|
|
|
using supports_op_less = decltype(meta_detail::supports_op_less_test(std::ref(std::declval<T&>()), std::ref(std::declval<U&>())));
|
|
|
|
template <typename T, typename U = T>
|
|
|
|
using supports_op_equal = decltype(meta_detail::supports_op_equal_test(std::ref(std::declval<T&>()), std::ref(std::declval<U&>())));
|
|
|
|
template <typename T, typename U = T>
|
|
|
|
using supports_op_less_equal = decltype(meta_detail::supports_op_less_equal_test(std::ref(std::declval<T&>()), std::ref(std::declval<U&>())));
|
|
|
|
template <typename T, typename U = std::ostream>
|
|
|
|
using supports_ostream_op = decltype(meta_detail::supports_ostream_op(std::ref(std::declval<T&>()), std::ref(std::declval<U&>())));
|
|
|
|
template <typename T>
|
|
|
|
using supports_adl_to_string = decltype(meta_detail::supports_adl_to_string(std::ref(std::declval<T&>())));
|
|
|
|
#else
|
2017-08-06 07:20:28 +08:00
|
|
|
template <typename T, typename U = T>
|
|
|
|
using supports_op_less = decltype(meta_detail::supports_op_less_test(std::declval<T&>(), std::declval<U&>()));
|
|
|
|
template <typename T, typename U = T>
|
|
|
|
using supports_op_equal = decltype(meta_detail::supports_op_equal_test(std::declval<T&>(), std::declval<U&>()));
|
|
|
|
template <typename T, typename U = T>
|
|
|
|
using supports_op_less_equal = decltype(meta_detail::supports_op_less_equal_test(std::declval<T&>(), std::declval<U&>()));
|
2017-08-11 15:24:17 +08:00
|
|
|
template <typename T, typename U = std::ostream>
|
|
|
|
using supports_ostream_op = decltype(meta_detail::supports_ostream_op(std::declval<T&>(), std::declval<U&>()));
|
2017-08-22 03:25:43 +08:00
|
|
|
template <typename T>
|
|
|
|
using supports_adl_to_string = decltype(meta_detail::supports_adl_to_string(std::declval<T&>()));
|
|
|
|
#endif
|
|
|
|
template <typename T>
|
|
|
|
using supports_to_string_member = meta::boolean<meta_detail::has_to_string_test<T>::value>;
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct is_callable : boolean<meta_detail::is_callable<T>::value> {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct has_begin_end : decltype(meta_detail::has_begin_end_impl::test<T>(0)) {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
struct has_key_value_pair : decltype(meta_detail::has_key_value_pair_impl::test<T>(0)) {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-06-24 06:07:24 +08:00
|
|
|
struct has_key_type : decltype(meta_detail::has_key_type_impl::test<T>(0)) {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-06-24 06:07:24 +08:00
|
|
|
struct has_mapped_type : decltype(meta_detail::has_mapped_type_impl::test<T>(0)) {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-07-10 00:00:57 +08:00
|
|
|
struct has_iterator : decltype(meta_detail::has_iterator_impl::test<T>(0)) {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-07-10 00:00:57 +08:00
|
|
|
struct has_value_type : decltype(meta_detail::has_value_type_impl::test<T>(0)) {};
|
|
|
|
|
2017-06-24 06:07:24 +08:00
|
|
|
template <typename T>
|
2017-08-06 07:20:28 +08:00
|
|
|
using has_push_back = meta::boolean<meta_detail::has_push_back_test<T>::value>;
|
|
|
|
|
2018-06-16 01:19:09 +08:00
|
|
|
template <typename T>
|
|
|
|
using has_max_size = meta::boolean<meta_detail::has_max_size_test<T>::value>;
|
|
|
|
|
2017-08-06 07:20:28 +08:00
|
|
|
template <typename T>
|
|
|
|
using has_insert = meta::boolean<meta_detail::has_insert_test<T>::value>;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
using has_insert_after = meta::boolean<meta_detail::has_insert_after_test<T>::value>;
|
|
|
|
|
2017-08-11 15:24:17 +08:00
|
|
|
template <typename T>
|
2018-11-19 02:06:01 +08:00
|
|
|
using has_size = meta::boolean<meta_detail::has_size_test<T>::value>;
|
2017-08-11 15:24:17 +08:00
|
|
|
|
2017-08-06 07:20:28 +08:00
|
|
|
template <typename T>
|
2018-11-19 02:06:01 +08:00
|
|
|
using is_associative = meta::all<has_key_type<T>, has_key_value_pair<T>, has_mapped_type<T>>;
|
2017-08-06 07:20:28 +08:00
|
|
|
|
|
|
|
template <typename T>
|
2018-11-19 02:06:01 +08:00
|
|
|
using is_lookup = meta::all<has_key_type<T>, has_value_type<T>>;
|
2017-06-24 06:07:24 +08:00
|
|
|
|
2017-12-20 17:58:32 +08:00
|
|
|
template <typename T>
|
2018-01-24 14:10:35 +08:00
|
|
|
struct is_matched_lookup : meta_detail::is_matched_lookup_impl<T, is_lookup<T>::value> {};
|
2017-12-20 17:58:32 +08:00
|
|
|
|
2018-02-03 14:29:06 +08:00
|
|
|
template <typename T>
|
2018-12-20 12:17:15 +08:00
|
|
|
using is_string_like = any<is_specialization_of<meta::unqualified_t<T>, std::basic_string>,
|
2018-04-18 00:29:03 +08:00
|
|
|
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
|
2018-12-20 12:17:15 +08:00
|
|
|
is_specialization_of<meta::unqualified_t<T>, std::basic_string_view>,
|
2018-03-01 08:20:20 +08:00
|
|
|
#else
|
2018-12-20 12:17:15 +08:00
|
|
|
is_specialization_of<meta::unqualified_t<T>, basic_string_view>,
|
2018-03-01 08:20:20 +08:00
|
|
|
#endif
|
2018-12-20 12:17:15 +08:00
|
|
|
meta::all<std::is_array<unqualified_t<T>>,
|
|
|
|
meta::any_same<meta::unqualified_t<std::remove_all_extents_t<meta::unqualified_t<T>>>, char, char16_t, char32_t, wchar_t>>>;
|
2018-02-03 14:29:06 +08:00
|
|
|
|
2017-02-17 18:46:39 +08:00
|
|
|
template <typename T>
|
2018-12-20 12:17:15 +08:00
|
|
|
using is_string_constructible
|
|
|
|
= any<meta::all<std::is_array<unqualified_t<T>>, std::is_same<meta::unqualified_t<std::remove_all_extents_t<meta::unqualified_t<T>>>, char>>,
|
|
|
|
std::is_same<unqualified_t<T>, const char*>, std::is_same<unqualified_t<T>, char>, std::is_same<unqualified_t<T>, std::string>,
|
|
|
|
std::is_same<unqualified_t<T>, std::initializer_list<char>>
|
2018-04-18 00:29:03 +08:00
|
|
|
#if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES
|
2018-12-20 12:17:15 +08:00
|
|
|
,
|
|
|
|
std::is_same<unqualified_t<T>, std::string_view>
|
2017-07-10 00:00:57 +08:00
|
|
|
#endif
|
2018-12-20 12:17:15 +08:00
|
|
|
>;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
using is_string_like_or_constructible = any<is_string_like<T>, is_string_constructible<T>>;
|
2017-02-17 18:46:39 +08:00
|
|
|
|
2017-06-08 00:33:59 +08:00
|
|
|
template <typename T>
|
|
|
|
struct is_pair : std::false_type {};
|
|
|
|
|
|
|
|
template <typename T1, typename T2>
|
|
|
|
struct is_pair<std::pair<T1, T2>> : std::true_type {};
|
|
|
|
|
2017-02-17 18:46:39 +08:00
|
|
|
template <typename T>
|
2018-12-20 12:17:15 +08:00
|
|
|
using is_c_str = any<std::is_same<std::decay_t<unqualified_t<T>>, const char*>, std::is_same<std::decay_t<unqualified_t<T>>, char*>,
|
|
|
|
std::is_same<unqualified_t<T>, std::string>>;
|
2017-02-17 18:46:39 +08:00
|
|
|
|
|
|
|
template <typename T>
|
2018-12-20 12:17:15 +08:00
|
|
|
struct is_move_only
|
|
|
|
: all<neg<std::is_reference<T>>, neg<std::is_copy_constructible<unqualified_t<T>>>, std::is_move_constructible<unqualified_t<T>>> {};
|
2017-02-17 18:46:39 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
using is_not_move_only = neg<is_move_only<T>>;
|
|
|
|
|
|
|
|
namespace meta_detail {
|
2018-03-02 11:08:27 +08:00
|
|
|
template <typename T, meta::disable<meta::is_specialization_of<meta::unqualified_t<T>, std::tuple>> = meta::enabler>
|
2017-02-17 18:46:39 +08:00
|
|
|
decltype(auto) force_tuple(T&& x) {
|
2018-03-17 04:47:09 +08:00
|
|
|
return std::tuple<std::decay_t<T>>(std::forward<T>(x));
|
2017-02-17 18:46:39 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 11:08:27 +08:00
|
|
|
template <typename T, meta::enable<meta::is_specialization_of<meta::unqualified_t<T>, std::tuple>> = meta::enabler>
|
2017-02-17 18:46:39 +08:00
|
|
|
decltype(auto) force_tuple(T&& x) {
|
|
|
|
return std::forward<T>(x);
|
|
|
|
}
|
2017-09-13 14:46:56 +08:00
|
|
|
} // namespace meta_detail
|
2017-02-17 18:46:39 +08:00
|
|
|
|
|
|
|
template <typename... X>
|
|
|
|
decltype(auto) tuplefy(X&&... x) {
|
|
|
|
return std::tuple_cat(meta_detail::force_tuple(std::forward<X>(x))...);
|
|
|
|
}
|
2017-05-29 22:32:37 +08:00
|
|
|
|
|
|
|
template <typename T, typename = void>
|
|
|
|
struct iterator_tag {
|
|
|
|
using type = std::input_iterator_tag;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
2018-12-20 12:17:15 +08:00
|
|
|
struct iterator_tag<T, conditional_t<false, typename std::iterator_traits<T>::iterator_category, void>> {
|
|
|
|
using type = typename std::iterator_traits<T>::iterator_category;
|
2017-05-29 22:32:37 +08:00
|
|
|
};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
} // namespace meta
|
2017-05-29 22:32:37 +08:00
|
|
|
|
2017-02-17 18:46:39 +08:00
|
|
|
namespace detail {
|
2017-08-07 20:47:17 +08:00
|
|
|
template <typename T>
|
|
|
|
struct is_pointer_like : std::is_pointer<T> {};
|
|
|
|
template <typename T, typename D>
|
|
|
|
struct is_pointer_like<std::unique_ptr<T, D>> : std::true_type {};
|
|
|
|
template <typename T>
|
|
|
|
struct is_pointer_like<std::shared_ptr<T>> : std::true_type {};
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
auto unwrap(T&& item) -> decltype(std::forward<T>(item)) {
|
|
|
|
return std::forward<T>(item);
|
|
|
|
}
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
T& unwrap(std::reference_wrapper<T> arg) {
|
|
|
|
return arg.get();
|
|
|
|
}
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T, meta::enable<meta::neg<is_pointer_like<meta::unqualified_t<T>>>> = meta::enabler>
|
2017-02-17 18:46:39 +08:00
|
|
|
auto deref(T&& item) -> decltype(std::forward<T>(item)) {
|
|
|
|
return std::forward<T>(item);
|
|
|
|
}
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T, meta::enable<is_pointer_like<meta::unqualified_t<T>>> = meta::enabler>
|
2017-08-11 15:24:17 +08:00
|
|
|
inline auto deref(T&& item) -> decltype(*std::forward<T>(item)) {
|
2017-08-07 20:47:17 +08:00
|
|
|
return *std::forward<T>(item);
|
2017-02-17 18:46:39 +08:00
|
|
|
}
|
|
|
|
|
2018-02-21 15:02:18 +08:00
|
|
|
template <typename T, meta::disable<is_pointer_like<meta::unqualified_t<T>>, meta::neg<std::is_pointer<meta::unqualified_t<T>>>> = meta::enabler>
|
|
|
|
auto deref_non_pointer(T&& item) -> decltype(std::forward<T>(item)) {
|
|
|
|
return std::forward<T>(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, meta::enable<is_pointer_like<meta::unqualified_t<T>>, meta::neg<std::is_pointer<meta::unqualified_t<T>>>> = meta::enabler>
|
|
|
|
inline auto deref_non_pointer(T&& item) -> decltype(*std::forward<T>(item)) {
|
|
|
|
return *std::forward<T>(item);
|
|
|
|
}
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
inline T* ptr(T& val) {
|
|
|
|
return std::addressof(val);
|
|
|
|
}
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
inline T* ptr(std::reference_wrapper<T> val) {
|
|
|
|
return std::addressof(val.get());
|
|
|
|
}
|
|
|
|
|
2017-09-13 14:46:56 +08:00
|
|
|
template <typename T>
|
2017-02-17 18:46:39 +08:00
|
|
|
inline T* ptr(T* val) {
|
|
|
|
return val;
|
|
|
|
}
|
2017-09-13 14:46:56 +08:00
|
|
|
} // namespace detail
|
|
|
|
} // namespace sol
|
2017-02-17 18:46:39 +08:00
|
|
|
|
|
|
|
#endif // SOL_TRAITS_HPP
|