http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/541ba92d/thirdparty/sol2-2.17.5/sol.hpp ---------------------------------------------------------------------- diff --git a/thirdparty/sol2-2.17.5/sol.hpp b/thirdparty/sol2-2.17.5/sol.hpp deleted file mode 100644 index c8812ac..0000000 --- a/thirdparty/sol2-2.17.5/sol.hpp +++ /dev/null @@ -1,14872 +0,0 @@ -// The MIT License (MIT) - -// Copyright (c) 2013-2017 Rapptz, ThePhD and contributors - -// 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. - -// This file was generated with a script. -// Generated 2017-07-01 15:02:51.956179 UTC -// This header was generated with sol v2.18.0 (revision da28527) -// https://github.com/ThePhD/sol2 - -#ifndef SOL_SINGLE_INCLUDE_HPP -#define SOL_SINGLE_INCLUDE_HPP - -// beginning of sol.hpp - -#ifndef SOL_HPP -#define SOL_HPP - -#if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER) -#define SOL_INSIDE_UNREAL -#endif // Unreal Engine 4 bullshit - -#ifdef SOL_INSIDE_UNREAL -#ifdef check -#define SOL_INSIDE_UNREAL_REMOVED_CHECK -#undef check -#endif -#endif // Unreal Engine 4 Bullshit - -#ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wshadow" -#pragma GCC diagnostic ignored "-Wconversion" -#if __GNUC__ > 6 -#pragma GCC diagnostic ignored "-Wnoexcept-type" -#endif -#elif defined _MSC_VER -#pragma warning( push ) -#pragma warning( disable : 4324 ) // structure was padded due to alignment specifier -#endif // g++ - -// beginning of sol/state.hpp - -// beginning of sol/state_view.hpp - -// beginning of sol/error.hpp - -#include <stdexcept> -#include <string> - -namespace sol { - namespace detail { - struct direct_error_tag {}; - const auto direct_error = direct_error_tag{}; - } // detail - - class error : public std::runtime_error { - private: - // Because VC++ is a fuccboi - std::string w; - public: - error(const std::string& str) : error(detail::direct_error, "lua: error: " + str) {} - error(std::string&& str) : error(detail::direct_error, "lua: error: " + std::move(str)) {} - error(detail::direct_error_tag, const std::string& str) : std::runtime_error(""), w(str) {} - error(detail::direct_error_tag, std::string&& str) : std::runtime_error(""), w(std::move(str)) {} - - error(const error& e) = default; - error(error&& e) = default; - error& operator=(const error& e) = default; - error& operator=(error&& e) = default; - - virtual const char* what() const noexcept override { - return w.c_str(); - } - }; - -} // sol - -// end of sol/error.hpp - -// beginning of sol/table.hpp - -// beginning of sol/table_core.hpp - -// beginning of sol/proxy.hpp - -// beginning of sol/traits.hpp - -// beginning of sol/tuple.hpp - -#include <tuple> -#include <cstddef> - -namespace sol { - namespace detail { - using swallow = std::initializer_list<int>; - } // detail - - template<typename... Args> - struct types { typedef std::make_index_sequence<sizeof...(Args)> indices; static constexpr std::size_t size() { return sizeof...(Args); } }; - namespace meta { - namespace detail { - template<typename... Args> - struct tuple_types_ { typedef types<Args...> type; }; - - template<typename... Args> - struct tuple_types_<std::tuple<Args...>> { typedef types<Args...> type; }; - } // detail - - template<typename T> - using unqualified = std::remove_cv<std::remove_reference_t<T>>; - - template<typename T> - using unqualified_t = typename unqualified<T>::type; - - template<typename... Args> - using tuple_types = typename detail::tuple_types_<Args...>::type; - - template<typename Arg> - struct pop_front_type; - - template<typename Arg> - using pop_front_type_t = typename pop_front_type<Arg>::type; - - template<typename... Args> - struct pop_front_type<types<Args...>> { typedef void front_type; typedef types<Args...> type; }; - - template<typename Arg, typename... Args> - struct pop_front_type<types<Arg, Args...>> { typedef Arg front_type; typedef types<Args...> type; }; - - template <std::size_t N, typename Tuple> - using tuple_element = std::tuple_element<N, unqualified_t<Tuple>>; - - template <std::size_t N, typename Tuple> - using tuple_element_t = std::tuple_element_t<N, unqualified_t<Tuple>>; - - template <std::size_t N, typename Tuple> - using unqualified_tuple_element = unqualified<tuple_element_t<N, Tuple>>; - - template <std::size_t N, typename Tuple> - using unqualified_tuple_element_t = unqualified_t<tuple_element_t<N, Tuple>>; - - } // meta -} // sol - -// end of sol/tuple.hpp - -// beginning of sol/bind_traits.hpp - -// beginning of sol/feature_test.hpp - -#if defined(__cpp_noexcept_function_type) -#ifndef SOL_NOEXCEPT_FUNCTION_TYPE -#define SOL_NOEXCEPT_FUNCTION_TYPE 1 -#endif // noexcept is part of a function's type -#endif - -#if defined(_WIN32) || defined(_MSC_VER) -#ifndef SOL_CODECVT_SUPPORT -#define SOL_CODECVT_SUPPORT 1 -#endif // sol codecvt support -#elif defined(__GNUC__) -#if __GNUC__ >= 5 -#ifndef SOL_CODECVT_SUPPORT -#define SOL_CODECVT_SUPPORT 1 -#endif // codecvt support -#endif // g++ 5.x.x (MinGW too) -#else -#endif // Windows/VC++ vs. g++ vs Others - -#ifdef _MSC_VER -#ifdef _DEBUG -#ifndef NDEBUG -#ifndef SOL_CHECK_ARGUMENTS -#endif // Check Arguments -#ifndef SOL_SAFE_USERTYPE -#define SOL_SAFE_USERTYPE -#endif // Safe Usertypes -#endif // NDEBUG -#endif // Debug - -#ifndef _CPPUNWIND -#ifndef SOL_NO_EXCEPTIONS -#define SOL_NO_EXCEPTIONS 1 -#endif -#endif // Automatic Exceptions - -#ifndef _CPPRTTI -#ifndef SOL_NO_RTTI -#define SOL_NO_RTTI 1 -#endif -#endif // Automatic RTTI - -#elif defined(__GNUC__) || defined(__clang__) - -#ifndef NDEBUG -#ifndef __OPTIMIZE__ -#ifndef SOL_CHECK_ARGUMENTS -#endif // Check Arguments -#ifndef SOL_SAFE_USERTYPE -#define SOL_SAFE_USERTYPE -#endif // Safe Usertypes -#endif // g++ optimizer flag -#endif // Not Debug - -#ifndef __EXCEPTIONS -#ifndef SOL_NO_EXCEPTIONS -#define SOL_NO_EXCEPTIONS 1 -#endif -#endif // No Exceptions - -#ifndef __GXX_RTTI -#ifndef SOL_NO_RTII -#define SOL_NO_RTTI 1 -#endif -#endif // No RTTI - -#endif // vc++ || clang++/g++ - -#ifndef SOL_SAFE_USERTYPE -#ifdef SOL_CHECK_ARGUMENTS -#define SOL_SAFE_USERTYPE -#endif // Turn on Safety for all -#endif // Safe Usertypes - -// end of sol/feature_test.hpp - -namespace sol { - namespace meta { - namespace meta_detail { - - template<class F> - struct check_deducible_signature { - struct nat {}; - template<class G> - static auto test(int) -> decltype(&G::operator(), void()); - template<class> - static auto test(...)->nat; - - using type = std::is_void<decltype(test<F>(0))>; - }; - } // meta_detail - - template<class F> - struct has_deducible_signature : meta_detail::check_deducible_signature<F>::type { }; - - namespace meta_detail { - - template <std::size_t I, typename T> - struct void_tuple_element : meta::tuple_element<I, T> {}; - - template <std::size_t I> - struct void_tuple_element<I, std::tuple<>> { typedef void type; }; - - template <std::size_t I, typename T> - using void_tuple_element_t = typename void_tuple_element<I, T>::type; - - template <bool it_is_noexcept, bool has_c_variadic, typename T, typename R, typename... Args> - struct basic_traits { - private: - typedef std::conditional_t<std::is_void<T>::value, int, T>& first_type; - - public: - static const bool is_noexcept = it_is_noexcept; - static const bool is_member_function = std::is_void<T>::value; - static const bool has_c_var_arg = has_c_variadic; - static const std::size_t arity = sizeof...(Args); - static const std::size_t free_arity = sizeof...(Args)+static_cast<std::size_t>(!std::is_void<T>::value); - typedef types<Args...> args_list; - typedef std::tuple<Args...> args_tuple; - typedef T object_type; - typedef R return_type; - typedef tuple_types<R> returns_list; - typedef R(function_type)(Args...); - typedef std::conditional_t<std::is_void<T>::value, args_list, types<first_type, Args...>> free_args_list; - typedef std::conditional_t<std::is_void<T>::value, R(Args...), R(first_type, Args...)> free_function_type; - typedef std::conditional_t<std::is_void<T>::value, R(*)(Args...), R(*)(first_type, Args...)> free_function_pointer_type; - typedef std::remove_pointer_t<free_function_pointer_type> signature_type; - template<std::size_t i> - using arg_at = void_tuple_element_t<i, args_tuple>; - }; - - template<typename Signature, bool b = has_deducible_signature<Signature>::value> - struct fx_traits : basic_traits<false, false, void, void> {}; - - // Free Functions - template<typename R, typename... Args> - struct fx_traits<R(Args...), false> : basic_traits<false, false, void, R, Args...> { - typedef R(*function_pointer_type)(Args...); - }; - - template<typename R, typename... Args> - struct fx_traits<R(*)(Args...), false> : basic_traits<false, false, void, R, Args...> { - typedef R(*function_pointer_type)(Args...); - }; - - template<typename R, typename... Args> - struct fx_traits<R(Args..., ...), false> : basic_traits<false, true, void, R, Args...> { - typedef R(*function_pointer_type)(Args..., ...); - }; - - template<typename R, typename... Args> - struct fx_traits<R(*)(Args..., ...), false> : basic_traits<false, true, void, R, Args...> { - typedef R(*function_pointer_type)(Args..., ...); - }; - - // Member Functions - /* C-Style Variadics */ - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...), false> : basic_traits<false, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...); - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...), false> : basic_traits<false, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...); - }; - - /* Const Volatile */ - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) const, false> : basic_traits<false, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) const; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) const, false> : basic_traits<false, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) const; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) const volatile, false> : basic_traits<false, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) const volatile; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) const volatile, false> : basic_traits<false, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) const volatile; - }; - - /* Member Function Qualifiers */ - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) &, false> : basic_traits<false, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) &; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) &, false> : basic_traits<false, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) &; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) const &, false> : basic_traits<false, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) const &; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) const &, false> : basic_traits<false, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) const &; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) const volatile &, false> : basic_traits<false, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) const volatile &; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) const volatile &, false> : basic_traits<false, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) const volatile &; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) && , false> : basic_traits<false, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) && ; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) && , false> : basic_traits<false, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) && ; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) const &&, false> : basic_traits<false, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) const &&; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) const &&, false> : basic_traits<false, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) const &&; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) const volatile &&, false> : basic_traits<false, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) const volatile &&; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) const volatile &&, false> : basic_traits<false, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) const volatile &&; - }; - -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE - - template<typename R, typename... Args> - struct fx_traits<R(Args...) noexcept, false> : basic_traits<true, false, void, R, Args...> { - typedef R(*function_pointer_type)(Args...) noexcept; - }; - - template<typename R, typename... Args> - struct fx_traits<R(*)(Args...) noexcept, false> : basic_traits<true, false, void, R, Args...> { - typedef R(*function_pointer_type)(Args...) noexcept; - }; - - template<typename R, typename... Args> - struct fx_traits<R(Args..., ...) noexcept, false> : basic_traits<true, true, void, R, Args...> { - typedef R(*function_pointer_type)(Args..., ...) noexcept; - }; - - template<typename R, typename... Args> - struct fx_traits<R(*)(Args..., ...) noexcept, false> : basic_traits<true, true, void, R, Args...> { - typedef R(*function_pointer_type)(Args..., ...) noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) noexcept, false> : basic_traits<true, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) noexcept, false> : basic_traits<true, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) noexcept; - }; - - /* Const Volatile */ - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) const noexcept, false> : basic_traits<true, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) const noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) const noexcept, false> : basic_traits<true, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) const noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) const volatile noexcept, false> : basic_traits<true, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) const volatile noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) const volatile noexcept, false> : basic_traits<true, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) const volatile noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) & noexcept, false> : basic_traits<true, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) & noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) & noexcept, false> : basic_traits<true, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) & noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) const & noexcept, false> : basic_traits<true, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) const & noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) const & noexcept, false> : basic_traits<true, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) const & noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) const volatile & noexcept, false> : basic_traits<true, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) const volatile & noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) const volatile & noexcept, false> : basic_traits<true, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) const volatile & noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) && noexcept , false> : basic_traits<true, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) && noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) && noexcept , false> : basic_traits<true, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) && noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) const && noexcept, false> : basic_traits<true, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) const && noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) const && noexcept, false> : basic_traits<true, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) const && noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args...) const volatile && noexcept, false> : basic_traits<true, false, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args...) const volatile && noexcept; - }; - - template<typename T, typename R, typename... Args> - struct fx_traits<R(T::*)(Args..., ...) const volatile && noexcept, false> : basic_traits<true, true, T, R, Args...> { - typedef R(T::* function_pointer_type)(Args..., ...) const volatile && noexcept; - }; - -#endif // noexcept is part of a function's type - - template<typename Signature> - struct fx_traits<Signature, true> : fx_traits<typename fx_traits<decltype(&Signature::operator())>::function_type, false> {}; - - template<typename Signature, bool b = std::is_member_object_pointer<Signature>::value> - struct callable_traits : fx_traits<std::decay_t<Signature>> { - - }; - - template<typename R, typename T> - struct callable_traits<R(T::*), true> { - typedef R Arg; - typedef T object_type; - using signature_type = R(T::*); - static const bool is_noexcept = false; - static const bool is_member_function = false; - static const std::size_t arity = 1; - static const std::size_t free_arity = 2; - typedef std::tuple<Arg> args_tuple; - typedef R return_type; - typedef types<Arg> args_list; - typedef types<T, Arg> free_args_list; - typedef meta::tuple_types<R> returns_list; - typedef R(function_type)(T&, R); - typedef R(*function_pointer_type)(T&, R); - typedef R(*free_function_pointer_type)(T&, R); - template<std::size_t i> - using arg_at = void_tuple_element_t<i, args_tuple>; - }; - - } // meta_detail - - template<typename Signature> - struct bind_traits : meta_detail::callable_traits<Signature> {}; - - template<typename Signature> - using function_args_t = typename bind_traits<Signature>::args_list; - - template<typename Signature> - using function_signature_t = typename bind_traits<Signature>::signature_type; - - template<typename Signature> - using function_return_t = typename bind_traits<Signature>::return_type; - - } // meta -} // sol - -// end of sol/bind_traits.hpp - -#include <type_traits> -#include <memory> -#include <functional> -#include <iterator> - -namespace sol { - template<std::size_t I> - using index_value = std::integral_constant<std::size_t, I>; - - namespace meta { - template<typename T> - struct identity { typedef T type; }; - - template<typename T> - using identity_t = typename identity<T>::type; - - template<typename... Args> - struct is_tuple : std::false_type { }; - - template<typename... Args> - struct is_tuple<std::tuple<Args...>> : std::true_type { }; - - 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> {}; - - template<typename T> - struct unwrapped { - typedef T type; - }; - - template<typename T> - struct unwrapped<std::reference_wrapper<T>> { - typedef T type; - }; - - template<typename T> - 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; - - template<typename T> - struct remove_member_pointer; - - template<typename R, typename T> - struct remove_member_pointer<R T::*> { - typedef R type; - }; - - template<typename R, typename T> - struct remove_member_pointer<R T::* const> { - typedef R type; - }; - - template<typename T> - using remove_member_pointer_t = remove_member_pointer<T>; - - template<template<typename...> class Templ, typename T> - struct is_specialization_of : std::false_type { }; - template<typename... T, template<typename...> class Templ> - struct is_specialization_of<Templ, Templ<T...>> : std::true_type { }; - - template<class T, class...> - struct all_same : std::true_type { }; - - 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> { }; - - template<class T, class...> - struct any_same : std::false_type { }; - - 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> { }; - - template<typename T> - using invoke_t = typename T::type; - - template<bool B> - using boolean = std::integral_constant<bool, B>; - - template<typename T> - using neg = boolean<!T::value>; - - template<typename Condition, typename Then, typename Else> - using condition = std::conditional_t<Condition::value, Then, Else>; - - template<typename... Args> - struct all : boolean<true> {}; - - template<typename T, typename... Args> - struct all<T, Args...> : condition<T, all<Args...>, boolean<false>> {}; - - template<typename... Args> - struct any : boolean<false> {}; - - template<typename T, typename... Args> - struct any<T, Args...> : condition<T, boolean<true>, any<Args...>> {}; - - enum class enable_t { - _ - }; - - constexpr const auto enabler = enable_t::_; - - template<bool value, typename T = void> - using disable_if_t = std::enable_if_t<!value, T>; - - template<typename... Args> - using enable = std::enable_if_t<all<Args...>::value, enable_t>; - - template<typename... Args> - using disable = std::enable_if_t<neg<all<Args...>>::value, enable_t>; - - template<typename... Args> - using disable_any = std::enable_if_t<neg<any<Args...>>::value, enable_t>; - - template<typename V, typename... Vs> - struct find_in_pack_v : boolean<false> { }; - - 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...>> { }; - - namespace meta_detail { - template<std::size_t I, typename T, typename... Args> - struct index_in_pack : std::integral_constant<std::size_t, SIZE_MAX> { }; - - template<std::size_t I, typename T, typename T1, typename... Args> - struct index_in_pack<I, T, T1, Args...> : std::conditional_t<std::is_same<T, T1>::value, std::integral_constant<std::ptrdiff_t, I>, index_in_pack<I + 1, T, Args...>> { }; - } - - template<typename T, typename... Args> - struct index_in_pack : meta_detail::index_in_pack<0, T, Args...> { }; - - template<typename T, typename List> - struct index_in : meta_detail::index_in_pack<0, T, List> { }; - - template<typename T, typename... Args> - struct index_in<T, types<Args...>> : meta_detail::index_in_pack<0, T, Args...> { }; - - template<std::size_t I, typename... Args> - struct at_in_pack {}; - - template<std::size_t I, typename... Args> - using at_in_pack_t = typename at_in_pack<I, Args...>::type; - - template<std::size_t I, typename Arg, typename... Args> - struct at_in_pack<I, Arg, Args...> : std::conditional<I == 0, Arg, at_in_pack_t<I - 1, Args...>> {}; - - template<typename Arg, typename... Args> - struct at_in_pack<0, Arg, Args...> { typedef Arg type; }; - - namespace meta_detail { - template<std::size_t Limit, std::size_t I, template<typename...> class Pred, typename... Ts> - struct count_for_pack : std::integral_constant<std::size_t, 0> {}; - template<std::size_t Limit, std::size_t I, template<typename...> class Pred, typename T, typename... Ts> - struct count_for_pack<Limit, I, Pred, T, Ts...> : std::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...> - > { }; - template<std::size_t I, template<typename...> class Pred, typename... Ts> - struct count_2_for_pack : std::integral_constant<std::size_t, 0> {}; - template<std::size_t I, template<typename...> class Pred, typename T, typename U, typename... Ts> - struct count_2_for_pack<I, Pred, T, U, Ts...> : std::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...> - > { }; - } // meta_detail - - template<template<typename...> class Pred, typename... Ts> - struct count_for_pack : meta_detail::count_for_pack<sizeof...(Ts), 0, Pred, Ts...> { }; - - template<template<typename...> class Pred, typename List> - struct count_for; - - template<template<typename...> class Pred, typename... Args> - struct count_for<Pred, types<Args...>> : count_for_pack<Pred, Args...> {}; - - 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...> { }; - - template<template<typename...> class Pred, typename... Ts> - struct count_2_for_pack : meta_detail::count_2_for_pack<0, Pred, Ts...> { }; - - template<typename... Args> - struct return_type { - typedef std::tuple<Args...> type; - }; - - template<typename T> - struct return_type<T> { - typedef T type; - }; - - template<> - struct return_type<> { - typedef void type; - }; - - template <typename... Args> - using return_type_t = typename return_type<Args...>::type; - - namespace meta_detail { - template <typename> struct always_true : std::true_type {}; - struct is_invokable_tester { - template <typename Fun, typename... Args> - always_true<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int); - template <typename...> - std::false_type static test(...); - }; - } // meta_detail - - 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 { - - template<typename T, bool isclass = std::is_class<unqualified_t<T>>::value> - struct is_callable : std::is_function<std::remove_pointer_t<T>> {}; - - template<typename T> - struct is_callable<T, true> { - using yes = char; - using no = struct { char s[2]; }; - - struct F { void operator()(); }; - struct Derived : T, F {}; - template<typename U, U> struct Check; - - template<typename V> - static no test(Check<void (F::*)(), &V::operator()>*); - - template<typename> - static yes test(...); - - static const bool value = sizeof(test<Derived>(0)) == sizeof(yes); - }; - - struct has_begin_end_impl { - template<typename T, typename U = unqualified_t<T>, - typename B = decltype(std::declval<U&>().begin()), - typename E = decltype(std::declval<U&>().end())> - static std::true_type test(int); - - template<typename...> - static std::false_type test(...); - }; - - struct has_key_type_impl { - template<typename T, typename U = unqualified_t<T>, - typename V = typename U::key_type> - static std::true_type test(int); - - template<typename...> - static std::false_type test(...); - }; - - struct has_mapped_type_impl { - template<typename T, typename U = unqualified_t<T>, - typename V = typename U::mapped_type> - static std::true_type test(int); - - template<typename...> - static std::false_type test(...); - }; - - struct has_key_value_pair_impl { - 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)> - static std::true_type test(int); - - template<typename...> - static std::false_type test(...); - }; - - template <typename T, typename U = T, typename = decltype(std::declval<T&>() < std::declval<U&>())> - std::true_type supports_op_less_test(const T&); - std::false_type supports_op_less_test(...); - template <typename T, typename U = T, typename = decltype(std::declval<T&>() == std::declval<U&>())> - std::true_type supports_op_equal_test(const T&); - std::false_type supports_op_equal_test(...); - template <typename T, typename U = T, typename = decltype(std::declval<T&>() <= std::declval<U&>())> - std::true_type supports_op_less_equal_test(const T&); - std::false_type supports_op_less_equal_test(...); - - } // meta_detail - - template <typename T> - using supports_op_less = decltype(meta_detail::supports_op_less_test(std::declval<T&>())); - template <typename T> - using supports_op_equal = decltype(meta_detail::supports_op_equal_test(std::declval<T&>())); - template <typename T> - using supports_op_less_equal = decltype(meta_detail::supports_op_less_equal_test(std::declval<T&>())); - - template<typename T> - struct is_callable : boolean<meta_detail::is_callable<T>::value> {}; - - template<typename T> - struct has_begin_end : decltype(meta_detail::has_begin_end_impl::test<T>(0)) {}; - - template<typename T> - struct has_key_value_pair : decltype(meta_detail::has_key_value_pair_impl::test<T>(0)) {}; - - template<typename T> - struct has_key_type : decltype(meta_detail::has_key_type_impl::test<T>(0)) {}; - - template<typename T> - struct has_mapped_type : decltype(meta_detail::has_mapped_type_impl::test<T>(0)) {}; - - template <typename T> - struct is_associative : meta::all<has_key_value_pair<T>, has_mapped_type<T>> {}; - - template <typename T> - using is_string_constructible = any<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>>>; - - template <typename T> - struct is_pair : std::false_type {}; - - template <typename T1, typename T2> - struct is_pair<std::pair<T1, T2>> : std::true_type {}; - - template <typename T> - 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> - >; - - template <typename T> - 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>> - > {}; - - template <typename T> - using is_not_move_only = neg<is_move_only<T>>; - - namespace meta_detail { - template <typename T, meta::disable<meta::is_specialization_of<std::tuple, meta::unqualified_t<T>>> = meta::enabler> - decltype(auto) force_tuple(T&& x) { - return std::forward_as_tuple(std::forward<T>(x)); - } - - template <typename T, meta::enable<meta::is_specialization_of<std::tuple, meta::unqualified_t<T>>> = meta::enabler> - decltype(auto) force_tuple(T&& x) { - return std::forward<T>(x); - } - } // meta_detail - - template <typename... X> - decltype(auto) tuplefy(X&&... x) { - return std::tuple_cat(meta_detail::force_tuple(std::forward<X>(x))...); - } - - template <typename T, typename = void> - struct iterator_tag { - using type = std::input_iterator_tag; - }; - - template <typename T> - struct iterator_tag<T, std::conditional_t<false, typename T::iterator_category, void>> { - using type = typename T::iterator_category; - }; - - } // meta - - namespace detail { - template <std::size_t I, typename Tuple> - decltype(auto) forward_get(Tuple&& tuple) { - return std::forward<meta::tuple_element_t<I, Tuple>>(std::get<I>(tuple)); - } - - template <std::size_t... I, typename Tuple> - auto forward_tuple_impl(std::index_sequence<I...>, Tuple&& tuple) -> decltype(std::tuple<decltype(forward_get<I>(tuple))...>(forward_get<I>(tuple)...)) { - return std::tuple<decltype(forward_get<I>(tuple))...>(std::move(std::get<I>(tuple))...); - } - - template <typename Tuple> - auto forward_tuple(Tuple&& tuple) { - auto x = forward_tuple_impl(std::make_index_sequence<std::tuple_size<meta::unqualified_t<Tuple>>::value>(), std::forward<Tuple>(tuple)); - return x; - } - - template<typename T> - auto unwrap(T&& item) -> decltype(std::forward<T>(item)) { - return std::forward<T>(item); - } - - template<typename T> - T& unwrap(std::reference_wrapper<T> arg) { - return arg.get(); - } - - template<typename T> - auto deref(T&& item) -> decltype(std::forward<T>(item)) { - return std::forward<T>(item); - } - - template<typename T> - inline T& deref(T* item) { - return *item; - } - - template<typename T, typename Dx> - inline std::add_lvalue_reference_t<T> deref(std::unique_ptr<T, Dx>& item) { - return *item; - } - - template<typename T> - inline std::add_lvalue_reference_t<T> deref(std::shared_ptr<T>& item) { - return *item; - } - - template<typename T, typename Dx> - inline std::add_lvalue_reference_t<T> deref(const std::unique_ptr<T, Dx>& item) { - return *item; - } - - template<typename T> - inline std::add_lvalue_reference_t<T> deref(const std::shared_ptr<T>& item) { - return *item; - } - - template<typename T> - inline T* ptr(T& val) { - return std::addressof(val); - } - - template<typename T> - inline T* ptr(std::reference_wrapper<T> val) { - return std::addressof(val.get()); - } - - template<typename T> - inline T* ptr(T* val) { - return val; - } - } // detail -} // sol - -// end of sol/traits.hpp - -// beginning of sol/object.hpp - -// beginning of sol/reference.hpp - -// beginning of sol/types.hpp - -// beginning of sol/optional.hpp - -// beginning of sol/compatibility.hpp - -// beginning of sol/compatibility/version.hpp - -#ifdef SOL_USING_CXX_LUA -#include <lua.h> -#include <lualib.h> -#include <lauxlib.h> -#ifdef SOL_USING_CXX_LUAJIT -#include <luajit.h> -#endif // C++ LuaJIT ... whatever that means -#else -#include <lua.hpp> -#endif // C++ Mangling for Lua - -#ifdef LUAJIT_VERSION -#ifndef SOL_LUAJIT -#define SOL_LUAJIT -#define SOL_LUAJIT_VERSION LUAJIT_VERSION_NUM -#endif // sol luajit -#endif // luajit - -#if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 502 -#define SOL_LUA_VERSION LUA_VERSION_NUM -#elif defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 -#define SOL_LUA_VERSION LUA_VERSION_NUM -#elif !defined(LUA_VERSION_NUM) -#define SOL_LUA_VERSION 500 -#else -#define SOL_LUA_VERSION 502 -#endif // Lua Version 502, 501 || luajit, 500 - -// end of sol/compatibility/version.hpp - -#ifndef SOL_NO_COMPAT - -#if defined(__cplusplus) && !defined(SOL_USING_CXX_LUA) -extern "C" { -#endif -// beginning of sol/compatibility/5.2.0.h - -#ifndef SOL_5_2_0_H -#define SOL_5_2_0_H - -#if SOL_LUA_VERSION < 503 - -inline int lua_isinteger(lua_State* L, int idx) { - if (lua_type(L, idx) != LUA_TNUMBER) - return 0; - // This is a very slipshod way to do the testing - // but lua_totingerx doesn't play ball nicely - // on older versions... - lua_Number n = lua_tonumber(L, idx); - lua_Integer i = lua_tointeger(L, idx); - if (i != n) - return 0; - // it's DEFINITELY an integer - return 1; -} - -#endif // SOL_LUA_VERSION == 502 -#endif // SOL_5_2_0_H -// end of sol/compatibility/5.2.0.h - -// beginning of sol/compatibility/5.1.0.h - -#ifndef SOL_5_1_0_H -#define SOL_5_1_0_H - -#if SOL_LUA_VERSION == 501 -/* Lua 5.1 */ - -#include <stddef.h> -#include <string.h> -#include <stdio.h> - -/* LuaJIT doesn't define these unofficial macros ... */ -#if !defined(LUAI_INT32) -#include <limits.h> -#if INT_MAX-20 < 32760 -#define LUAI_INT32 long -#define LUAI_UINT32 unsigned long -#elif INT_MAX > 2147483640L -#define LUAI_INT32 int -#define LUAI_UINT32 unsigned int -#else -#error "could not detect suitable lua_Unsigned datatype" -#endif -#endif - -/* LuaJIT does not have the updated error codes for thread status/function returns */ -#ifndef LUA_ERRGCMM -#define LUA_ERRGCMM (LUA_ERRERR + 2) -#endif // LUA_ERRGCMM - -/* LuaJIT does not support continuation contexts / return error codes? */ -#ifndef LUA_KCONTEXT -#define LUA_KCONTEXT std::ptrdiff_t -typedef LUA_KCONTEXT lua_KContext; -typedef int(*lua_KFunction) (lua_State *L, int status, lua_KContext ctx); -#endif // LUA_KCONTEXT - -#define LUA_OPADD 0 -#define LUA_OPSUB 1 -#define LUA_OPMUL 2 -#define LUA_OPDIV 3 -#define LUA_OPMOD 4 -#define LUA_OPPOW 5 -#define LUA_OPUNM 6 -#define LUA_OPEQ 0 -#define LUA_OPLT 1 -#define LUA_OPLE 2 - -typedef LUAI_UINT32 lua_Unsigned; - -typedef struct luaL_Buffer_52 { - luaL_Buffer b; /* make incorrect code crash! */ - char *ptr; - size_t nelems; - size_t capacity; - lua_State *L2; -} luaL_Buffer_52; -#define luaL_Buffer luaL_Buffer_52 - -#define lua_tounsigned(L, i) lua_tounsignedx(L, i, NULL) - -#define lua_rawlen(L, i) lua_objlen(L, i) - -inline void lua_callk(lua_State *L, int nargs, int nresults, lua_KContext, lua_KFunction) { - // should probably warn the user of Lua 5.1 that continuation isn't supported... - lua_call(L, nargs, nresults); -} -inline int lua_pcallk(lua_State *L, int nargs, int nresults, int errfunc, lua_KContext, lua_KFunction) { - // should probably warn the user of Lua 5.1 that continuation isn't supported... - return lua_pcall(L, nargs, nresults, errfunc); -} -void lua_arith(lua_State *L, int op); -int lua_compare(lua_State *L, int idx1, int idx2, int op); -void lua_pushunsigned(lua_State *L, lua_Unsigned n); -lua_Unsigned luaL_checkunsigned(lua_State *L, int i); -lua_Unsigned lua_tounsignedx(lua_State *L, int i, int *isnum); -lua_Unsigned luaL_optunsigned(lua_State *L, int i, lua_Unsigned def); -lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum); -void lua_len(lua_State *L, int i); -int luaL_len(lua_State *L, int i); -const char *luaL_tolstring(lua_State *L, int idx, size_t *len); -void luaL_requiref(lua_State *L, char const* modname, lua_CFunction openf, int glb); - -#define luaL_buffinit luaL_buffinit_52 -void luaL_buffinit(lua_State *L, luaL_Buffer_52 *B); - -#define luaL_prepbuffsize luaL_prepbuffsize_52 -char *luaL_prepbuffsize(luaL_Buffer_52 *B, size_t s); - -#define luaL_addlstring luaL_addlstring_52 -void luaL_addlstring(luaL_Buffer_52 *B, const char *s, size_t l); - -#define luaL_addvalue luaL_addvalue_52 -void luaL_addvalue(luaL_Buffer_52 *B); - -#define luaL_pushresult luaL_pushresult_52 -void luaL_pushresult(luaL_Buffer_52 *B); - -#undef luaL_buffinitsize -#define luaL_buffinitsize(L, B, s) \ - (luaL_buffinit(L, B), luaL_prepbuffsize(B, s)) - -#undef luaL_prepbuffer -#define luaL_prepbuffer(B) \ - luaL_prepbuffsize(B, LUAL_BUFFERSIZE) - -#undef luaL_addchar -#define luaL_addchar(B, c) \ - ((void)((B)->nelems < (B)->capacity || luaL_prepbuffsize(B, 1)), \ - ((B)->ptr[(B)->nelems++] = (c))) - -#undef luaL_addsize -#define luaL_addsize(B, s) \ - ((B)->nelems += (s)) - -#undef luaL_addstring -#define luaL_addstring(B, s) \ - luaL_addlstring(B, s, strlen(s)) - -#undef luaL_pushresultsize -#define luaL_pushresultsize(B, s) \ - (luaL_addsize(B, s), luaL_pushresult(B)) - -typedef struct kepler_lua_compat_get_string_view { - const char *s; - size_t size; -} kepler_lua_compat_get_string_view; - -inline const char* kepler_lua_compat_get_string(lua_State* L, void* ud, size_t* size) { - kepler_lua_compat_get_string_view* ls = (kepler_lua_compat_get_string_view*) ud; - (void)L; - if (ls->size == 0) return NULL; - *size = ls->size; - ls->size = 0; - return ls->s; -} - -#if !defined(SOL_LUAJIT) || (SOL_LUAJIT_VERSION < 20100) - -inline int luaL_loadbufferx(lua_State* L, const char* buff, size_t size, const char* name, const char*) { - kepler_lua_compat_get_string_view ls; - ls.s = buff; - ls.size = size; - return lua_load(L, kepler_lua_compat_get_string, &ls, name/*, mode*/); -} - -#endif // LuaJIT 2.1.x beta and beyond - -#endif /* Lua 5.1 */ - -#endif // SOL_5_1_0_H -// end of sol/compatibility/5.1.0.h - -// beginning of sol/compatibility/5.0.0.h - -#ifndef SOL_5_0_0_H -#define SOL_5_0_0_H - -#if SOL_LUA_VERSION < 501 -/* Lua 5.0 */ - -#define LUA_QL(x) "'" x "'" -#define LUA_QS LUA_QL("%s") - -#define luaL_Reg luaL_reg - -#define luaL_opt(L, f, n, d) \ - (lua_isnoneornil(L, n) ? (d) : f(L, n)) - -#define luaL_addchar(B,c) \ - ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ - (*(B)->p++ = (char)(c))) - -#endif // Lua 5.0 - -#endif // SOL_5_0_0_H -// end of sol/compatibility/5.0.0.h - -// beginning of sol/compatibility/5.x.x.h - -#ifndef SOL_5_X_X_H -#define SOL_5_X_X_H - -#if SOL_LUA_VERSION < 502 - -#define LUA_RIDX_GLOBALS LUA_GLOBALSINDEX - -#define LUA_OK 0 - -#define lua_pushglobaltable(L) \ - lua_pushvalue(L, LUA_GLOBALSINDEX) - -void luaL_checkversion(lua_State *L); - -#if !defined(SOL_LUAJIT_VERSION) || SOL_LUAJIT_VERSION < 20100 -void lua_copy(lua_State *L, int from, int to); -lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum); -lua_Number lua_tonumberx(lua_State *L, int i, int *isnum); -const lua_Number *lua_version(lua_State *L); -void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup); -void luaL_setmetatable(lua_State *L, const char *tname); -void *luaL_testudata(lua_State *L, int i, const char *tname); -#define luaL_newlib(L, l) \ - (lua_newtable((L)),luaL_setfuncs((L), (l), 0)) -#endif // LuaJIT-2.1.0-beta3 added these compatibility functions - -int lua_absindex(lua_State *L, int i); -void lua_rawgetp(lua_State *L, int i, const void *p); -void lua_rawsetp(lua_State *L, int i, const void *p); -void lua_getuservalue(lua_State *L, int i); -void lua_setuservalue(lua_State *L, int i); -int luaL_getsubtable(lua_State *L, int i, const char *name); -void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level); -int luaL_fileresult(lua_State *L, int stat, const char *fname); - -#endif // Lua 5.1 and below - -#endif // SOL_5_X_X_H -// end of sol/compatibility/5.x.x.h - -// beginning of sol/compatibility/5.x.x.inl - -#ifndef SOL_5_X_X_INL -#define SOL_5_X_X_INL - -#if SOL_LUA_VERSION < 502 - -#include <errno.h> - -#define PACKAGE_KEY "_sol.package" - -inline int lua_absindex(lua_State *L, int i) { - if (i < 0 && i > LUA_REGISTRYINDEX) - i += lua_gettop(L) + 1; - return i; -} - -#if !defined(SOL_LUAJIT_VERSION) || SOL_LUAJIT_VERSION < 20100 -inline void lua_copy(lua_State *L, int from, int to) { - int abs_to = lua_absindex(L, to); - luaL_checkstack(L, 1, "not enough stack slots"); - lua_pushvalue(L, from); - lua_replace(L, abs_to); -} - -inline lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum) { - lua_Integer n = lua_tointeger(L, i); - if (isnum != NULL) { - *isnum = (n != 0 || lua_isnumber(L, i)); - } - return n; -} - -inline lua_Number lua_tonumberx(lua_State *L, int i, int *isnum) { - lua_Number n = lua_tonumber(L, i); - if (isnum != NULL) { - *isnum = (n != 0 || lua_isnumber(L, i)); - } - return n; -} - -inline const lua_Number *lua_version(lua_State *L) { - static const lua_Number version = LUA_VERSION_NUM; - if (L == NULL) return &version; - // TODO: wonky hacks to get at the inside of the incomplete type lua_State? - //else return L->l_G->version; - else return &version; -} - -/* -** Adapted from Lua 5.2.0 -*/ -inline void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { - luaL_checkstack(L, nup + 1, "too many upvalues"); - for (; l->name != NULL; l++) { /* fill the table with given functions */ - int i; - lua_pushstring(L, l->name); - for (i = 0; i < nup; i++) /* copy upvalues to the top */ - lua_pushvalue(L, -(nup + 1)); - lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ - lua_settable(L, -(nup + 3)); /* table must be below the upvalues, the name and the closure */ - } - lua_pop(L, nup); /* remove upvalues */ -} - -inline void luaL_setmetatable(lua_State *L, const char *tname) { - luaL_checkstack(L, 1, "not enough stack slots"); - luaL_getmetatable(L, tname); - lua_setmetatable(L, -2); -} - -inline void *luaL_testudata(lua_State *L, int i, const char *tname) { - void *p = lua_touserdata(L, i); - luaL_checkstack(L, 2, "not enough stack slots"); - if (p == NULL || !lua_getmetatable(L, i)) - return NULL; - else { - int res = 0; - luaL_getmetatable(L, tname); - res = lua_rawequal(L, -1, -2); - lua_pop(L, 2); - if (!res) - p = NULL; - } - return p; -} -#endif - -inline void lua_rawgetp(lua_State *L, int i, const void *p) { - int abs_i = lua_absindex(L, i); - lua_pushlightuserdata(L, (void*)p); - lua_rawget(L, abs_i); -} - -inline void lua_rawsetp(lua_State *L, int i, const void *p) { - int abs_i = lua_absindex(L, i); - luaL_checkstack(L, 1, "not enough stack slots"); - lua_pushlightuserdata(L, (void*)p); - lua_insert(L, -2); - lua_rawset(L, abs_i); -} - -inline static void push_package_table(lua_State *L) { - lua_pushliteral(L, PACKAGE_KEY); - lua_rawget(L, LUA_REGISTRYINDEX); - if (!lua_istable(L, -1)) { - lua_pop(L, 1); - /* try to get package table from globals */ - lua_pushliteral(L, "package"); - lua_rawget(L, LUA_GLOBALSINDEX); - if (lua_istable(L, -1)) { - lua_pushliteral(L, PACKAGE_KEY); - lua_pushvalue(L, -2); - lua_rawset(L, LUA_REGISTRYINDEX); - } - } -} - -inline void lua_getuservalue(lua_State *L, int i) { - luaL_checktype(L, i, LUA_TUSERDATA); - luaL_checkstack(L, 2, "not enough stack slots"); - lua_getfenv(L, i); - lua_pushvalue(L, LUA_GLOBALSINDEX); - if (lua_rawequal(L, -1, -2)) { - lua_pop(L, 1); - lua_pushnil(L); - lua_replace(L, -2); - } - else { - lua_pop(L, 1); - push_package_table(L); - if (lua_rawequal(L, -1, -2)) { - lua_pop(L, 1); - lua_pushnil(L); - lua_replace(L, -2); - } - else - lua_pop(L, 1); - } -} - -inline void lua_setuservalue(lua_State *L, int i) { - luaL_checktype(L, i, LUA_TUSERDATA); - if (lua_isnil(L, -1)) { - luaL_checkstack(L, 1, "not enough stack slots"); - lua_pushvalue(L, LUA_GLOBALSINDEX); - lua_replace(L, -2); - } - lua_setfenv(L, i); -} - -inline int luaL_getsubtable(lua_State *L, int i, const char *name) { - int abs_i = lua_absindex(L, i); - luaL_checkstack(L, 3, "not enough stack slots"); - lua_pushstring(L, name); - lua_gettable(L, abs_i); - if (lua_istable(L, -1)) - return 1; - lua_pop(L, 1); - lua_newtable(L); - lua_pushstring(L, name); - lua_pushvalue(L, -2); - lua_settable(L, abs_i); - return 0; -} - -#ifndef SOL_LUAJIT -inline static int countlevels(lua_State *L) { - lua_Debug ar; - int li = 1, le = 1; - /* find an upper bound */ - while (lua_getstack(L, le, &ar)) { li = le; le *= 2; } - /* do a binary search */ - while (li < le) { - int m = (li + le) / 2; - if (lua_getstack(L, m, &ar)) li = m + 1; - else le = m; - } - return le - 1; -} - -inline static int findfield(lua_State *L, int objidx, int level) { - if (level == 0 || !lua_istable(L, -1)) - return 0; /* not found */ - lua_pushnil(L); /* start 'next' loop */ - while (lua_next(L, -2)) { /* for each pair in table */ - if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */ - if (lua_rawequal(L, objidx, -1)) { /* found object? */ - lua_pop(L, 1); /* remove value (but keep name) */ - return 1; - } - else if (findfield(L, objidx, level - 1)) { /* try recursively */ - lua_remove(L, -2); /* remove table (but keep name) */ - lua_pushliteral(L, "."); - lua_insert(L, -2); /* place '.' between the two names */ - lua_concat(L, 3); - return 1; - } - } - lua_pop(L, 1); /* remove value */ - } - return 0; /* not found */ -} - -inline static int pushglobalfuncname(lua_State *L, lua_Debug *ar) { - int top = lua_gettop(L); - lua_getinfo(L, "f", ar); /* push function */ - lua_pushvalue(L, LUA_GLOBALSINDEX); - if (findfield(L, top + 1, 2)) { - lua_copy(L, -1, top + 1); /* move name to proper place */ - lua_pop(L, 2); /* remove pushed values */ - return 1; - } - else { - lua_settop(L, top); /* remove function and global table */ - return 0; - } -} - -inline static void pushfuncname(lua_State *L, lua_Debug *ar) { - if (*ar->namewhat != '\0') /* is there a name? */ - lua_pushfstring(L, "function " LUA_QS, ar->name); - else if (*ar->what == 'm') /* main? */ - lua_pushliteral(L, "main chunk"); - else if (*ar->what == 'C') { - if (pushglobalfuncname(L, ar)) { - lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1)); - lua_remove(L, -2); /* remove name */ - } - else - lua_pushliteral(L, "?"); - } - else - lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined); -} - -#define LEVELS1 12 /* size of the first part of the stack */ -#define LEVELS2 10 /* size of the second part of the stack */ - -inline void luaL_traceback(lua_State *L, lua_State *L1, - const char *msg, int level) { - lua_Debug ar; - int top = lua_gettop(L); - int numlevels = countlevels(L1); - int mark = (numlevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0; - if (msg) lua_pushfstring(L, "%s\n", msg); - lua_pushliteral(L, "stack traceback:"); - while (lua_getstack(L1, level++, &ar)) { - if (level == mark) { /* too many levels? */ - lua_pushliteral(L, "\n\t..."); /* add a '...' */ - level = numlevels - LEVELS2; /* and skip to last ones */ - } - else { - lua_getinfo(L1, "Slnt", &ar); - lua_pushfstring(L, "\n\t%s:", ar.short_src); - if (ar.currentline > 0) - lua_pushfstring(L, "%d:", ar.currentline); - lua_pushliteral(L, " in "); - pushfuncname(L, &ar); - lua_concat(L, lua_gettop(L) - top); - } - } - lua_concat(L, lua_gettop(L) - top); -} -#endif - -inline static void luaL_checkversion_(lua_State *L, lua_Number ver) { - const lua_Number* v = lua_version(L); - if (v != lua_version(NULL)) - luaL_error(L, "multiple Lua VMs detected"); - else if (*v != ver) - luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f", - ver, *v); - /* check conversions number -> integer types */ - lua_pushnumber(L, -(lua_Number)0x1234); - if (lua_tointeger(L, -1) != -0x1234 || - lua_tounsigned(L, -1) != (lua_Unsigned)-0x1234) - luaL_error(L, "bad conversion number->int;" - " must recompile Lua with proper settings"); - lua_pop(L, 1); -} - -inline void luaL_checkversion(lua_State* L) { - luaL_checkversion_(L, LUA_VERSION_NUM); -} - -#ifndef SOL_LUAJIT -inline int luaL_fileresult(lua_State *L, int stat, const char *fname) { - int en = errno; /* calls to Lua API may change this value */ - if (stat) { - lua_pushboolean(L, 1); - return 1; - } - else { - char buf[1024]; -#if defined(__GLIBC__) || defined(_POSIX_VERSION) || defined(__APPLE__) - strerror_r(en, buf, 1024); -#else - strerror_s(buf, 1024, en); -#endif - lua_pushnil(L); - if (fname) - lua_pushfstring(L, "%s: %s", fname, buf); - else - lua_pushstring(L, buf); - lua_pushnumber(L, (lua_Number)en); - return 3; - } -} -#endif // luajit -#endif // Lua 5.0 or Lua 5.1 - -#if SOL_LUA_VERSION == 501 - -typedef LUAI_INT32 LUA_INT32; - -/********************************************************************/ -/* extract of 5.2's luaconf.h */ -/* detects proper defines for faster unsigned<->number conversion */ -/* see copyright notice at the end of this file */ -/********************************************************************/ - -#if !defined(LUA_ANSI) && defined(_WIN32) && !defined(_WIN32_WCE) -#define LUA_WIN /* enable goodies for regular Windows platforms */ -#endif - -#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */ - -/* Microsoft compiler on a Pentium (32 bit) ? */ -#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */ - -#define LUA_MSASMTRICK -#define LUA_IEEEENDIAN 0 -#define LUA_NANTRICK - -/* pentium 32 bits? */ -#elif defined(__i386__) || defined(__i386) || defined(__X86__) /* }{ */ - -#define LUA_IEEE754TRICK -#define LUA_IEEELL -#define LUA_IEEEENDIAN 0 -#define LUA_NANTRICK - -/* pentium 64 bits? */ -#elif defined(__x86_64) /* }{ */ - -#define LUA_IEEE754TRICK -#define LUA_IEEEENDIAN 0 - -#elif defined(__POWERPC__) || defined(__ppc__) /* }{ */ - -#define LUA_IEEE754TRICK -#define LUA_IEEEENDIAN 1 - -#else /* }{ */ - -/* assume IEEE754 and a 32-bit integer type */ -#define LUA_IEEE754TRICK - -#endif /* } */ - -#endif /* } */ - -/********************************************************************/ -/* extract of 5.2's llimits.h */ -/* gives us lua_number2unsigned and lua_unsigned2number */ -/* see copyright notice just below this one here */ -/********************************************************************/ - -/********************************************************************* -* This file contains parts of Lua 5.2's source code: -* -* Copyright (C) 1994-2013 Lua.org, PUC-Rio. -* -* 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. -*********************************************************************/ - -#if defined(MS_ASMTRICK) || defined(LUA_MSASMTRICK) /* { */ -/* trick with Microsoft assembler for X86 */ - -#define lua_number2unsigned(i,n) \ - {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;} - -#elif defined(LUA_IEEE754TRICK) /* }{ */ -/* the next trick should work on any machine using IEEE754 with -a 32-bit int type */ - -union compat52_luai_Cast { double l_d; LUA_INT32 l_p[2]; }; - -#if !defined(LUA_IEEEENDIAN) /* { */ -#define LUAI_EXTRAIEEE \ - static const union compat52_luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)}; -#define LUA_IEEEENDIANLOC (ieeeendian.l_p[1] == 33) -#else -#define LUA_IEEEENDIANLOC LUA_IEEEENDIAN -#define LUAI_EXTRAIEEE /* empty */ -#endif /* } */ - -#define lua_number2int32(i,n,t) \ - { LUAI_EXTRAIEEE \ - volatile union compat52_luai_Cast u; u.l_d = (n) + 6755399441055744.0; \ - (i) = (t)u.l_p[LUA_IEEEENDIANLOC]; } - -#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned) - -#endif /* } */ - -/* the following definitions always work, but may be slow */ - -#if !defined(lua_number2unsigned) /* { */ -/* the following definition assures proper modulo behavior */ -#if defined(LUA_NUMBER_DOUBLE) || defined(LUA_NUMBER_FLOAT) -#include <math.h> -#define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1) -#define lua_number2unsigned(i,n) \ - ((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED)) -#else -#define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n)) -#endif -#endif /* } */ - -#if !defined(lua_unsigned2number) -/* on several machines, coercion from unsigned to double is slow, -so it may be worth to avoid */ -#define lua_unsigned2number(u) \ - (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u)) -#endif - -/********************************************************************/ - -inline static void compat52_call_lua(lua_State *L, char const code[], size_t len, - int nargs, int nret) { - lua_rawgetp(L, LUA_REGISTRYINDEX, (void*)code); - if (lua_type(L, -1) != LUA_TFUNCTION) { - lua_pop(L, 1); - if (luaL_loadbuffer(L, code, len, "=none")) - lua_error(L); - lua_pushvalue(L, -1); - lua_rawsetp(L, LUA_REGISTRYINDEX, (void*)code); - } - lua_insert(L, -nargs - 1); - lua_call(L, nargs, nret); -} - -static const char compat52_arith_code[] = { - "local op,a,b=...\n" - "if op==0 then return a+b\n" - "elseif op==1 then return a-b\n" - "elseif op==2 then return a*b\n" - "elseif op==3 then return a/b\n" - "elseif op==4 then return a%b\n" - "elseif op==5 then return a^b\n" - "elseif op==6 then return -a\n" - "end\n" -}; - -inline void lua_arith(lua_State *L, int op) { - if (op < LUA_OPADD || op > LUA_OPUNM) - luaL_error(L, "invalid 'op' argument for lua_arith"); - luaL_checkstack(L, 5, "not enough stack slots"); - if (op == LUA_OPUNM) - lua_pushvalue(L, -1); - lua_pushnumber(L, op); - lua_insert(L, -3); - compat52_call_lua(L, compat52_arith_code, - sizeof(compat52_arith_code) - 1, 3, 1); -} - -static const char compat52_compare_code[] = { - "local a,b=...\n" - "return a<=b\n" -}; - -inline int lua_compare(lua_State *L, int idx1, int idx2, int op) { - int result = 0; - switch (op) { - case LUA_OPEQ: - return lua_equal(L, idx1, idx2); - case LUA_OPLT: - return lua_lessthan(L, idx1, idx2); - case LUA_OPLE: - luaL_checkstack(L, 5, "not enough stack slots"); - idx1 = lua_absindex(L, idx1); - idx2 = lua_absindex(L, idx2); - lua_pushvalue(L, idx1); - lua_pushvalue(L, idx2); - compat52_call_lua(L, compat52_compare_code, - sizeof(compat52_compare_code) - 1, 2, 1); - result = lua_toboolean(L, -1); - lua_pop(L, 1); - return result; - default: - luaL_error(L, "invalid 'op' argument for lua_compare"); - } - return 0; -} - -inline void lua_pushunsigned(lua_State *L, lua_Unsigned n) { - lua_pushnumber(L, lua_unsigned2number(n)); -} - -inline lua_Unsigned luaL_checkunsigned(lua_State *L, int i) { - lua_Unsigned result; - lua_Number n = lua_tonumber(L, i); - if (n == 0 && !lua_isnumber(L, i)) - luaL_checktype(L, i, LUA_TNUMBER); - lua_number2unsigned(result, n); - return result; -} - -inline lua_Unsigned lua_tounsignedx(lua_State *L, int i, int *isnum) { - lua_Unsigned result; - lua_Number n = lua_tonumberx(L, i, isnum); - lua_number2unsigned(result, n); - return result; -} - -inline lua_Unsigned luaL_optunsigned(lua_State *L, int i, lua_Unsigned def) { - return luaL_opt(L, luaL_checkunsigned, i, def); -} - -inline void lua_len(lua_State *L, int i) { - switch (lua_type(L, i)) { - case LUA_TSTRING: /* fall through */ - case LUA_TTABLE: - if (!luaL_callmeta(L, i, "__len")) - lua_pushnumber(L, (int)lua_objlen(L, i)); - break; - case LUA_TUSERDATA: - if (luaL_callmeta(L, i, "__len")) - break; - /* maybe fall through */ - default: - luaL_error(L, "attempt to get length of a %s value", - lua_typename(L, lua_type(L, i))); - } -} - -inline int luaL_len(lua_State *L, int i) { - int res = 0, isnum = 0; - luaL_checkstack(L, 1, "not enough stack slots"); - lua_len(L, i); - res = (int)lua_tointegerx(L, -1, &isnum); - lua_pop(L, 1); - if (!isnum) - luaL_error(L, "object length is not a number"); - return res; -} - -inline const char *luaL_tolstring(lua_State *L, int idx, size_t *len) { - if (!luaL_callmeta(L, idx, "__tostring")) { - int t = lua_type(L, idx); - switch (t) { - case LUA_TNIL: - lua_pushliteral(L, "nil"); - break; - case LUA_TSTRING: - case LUA_TNUMBER: - lua_pushvalue(L, idx); - break; - case LUA_TBOOLEAN: - if (lua_toboolean(L, idx)) - lua_pushliteral(L, "true"); - else - lua_pushliteral(L, "false"); - break; - default: - lua_pushfstring(L, "%s: %p", lua_typename(L, t), - lua_topointer(L, idx)); - break; - } - } - return lua_tolstring(L, -1, len); -} - -inline void luaL_requiref(lua_State *L, char const* modname, - lua_CFunction openf, int glb) { - luaL_checkstack(L, 3, "not enough stack slots"); - lua_pushcfunction(L, openf); - lua_pushstring(L, modname); - lua_call(L, 1, 1); - lua_getglobal(L, "package"); - if (lua_istable(L, -1) == 0) { - lua_pop(L, 1); - lua_createtable(L, 0, 16); - lua_setglobal(L, "package"); - lua_getglobal(L, "package"); - } - lua_getfield(L, -1, "loaded"); - if (lua_istable(L, -1) == 0) { - lua_pop(L, 1); - lua_createtable(L, 0, 1); - lua_setfield(L, -2, "loaded"); - lua_getfield(L, -1, "loaded"); - } - lua_replace(L, -2); - lua_pushvalue(L, -2); - lua_setfield(L, -2, modname); - lua_pop(L, 1); - if (glb) { - lua_pushvalue(L, -1); - lua_setglobal(L, modname); - } -} - -inline void luaL_buffinit(lua_State *L, luaL_Buffer_52 *B) { - /* make it crash if used via pointer to a 5.1-style luaL_Buffer */ - B->b.p = NULL; - B->b.L = NULL; - B->b.lvl = 0; - /* reuse the buffer from the 5.1-style luaL_Buffer though! */ - B->ptr = B->b.buffer; - B->capacity = LUAL_BUFFERSIZE; - B->nelems = 0; - B->L2 = L; -} - -inline char *luaL_prepbuffsize(luaL_Buffer_52 *B, size_t s) { - if (B->capacity - B->nelems < s) { /* needs to grow */ - char* newptr = NULL; - size_t newcap = B->capacity * 2; - if (newcap - B->nelems < s) - newcap = B->nelems + s; - if (newcap < B->capacity) /* overflow */ - luaL_error(B->L2, "buffer too large"); - newptr = (char*)lua_newuserdata(B->L2, newcap); - memcpy(newptr, B->ptr, B->nelems); - if (B->ptr != B->b.buffer) - lua_replace(B->L2, -2); /* remove old buffer */ - B->ptr = newptr; - B->capacity = newcap; - } - return B->ptr + B->nelems; -} - -inline void luaL_addlstring(luaL_Buffer_52 *B, const char *s, size_t l) { - memcpy(luaL_prepbuffsize(B, l), s, l); - luaL_addsize(B, l); -} - -inline void luaL_addvalue(luaL_Buffer_52 *B) { - size_t len = 0; - const char *s = lua_tolstring(B->L2, -1, &len); - if (!s) - luaL_error(B->L2, "cannot convert value to string"); - if (B->ptr != B->b.buffer) - lua_insert(B->L2, -2); /* userdata buffer must be at stack top */ - luaL_addlstring(B, s, len); - lua_remove(B->L2, B->ptr != B->b.buffer ? -2 : -1); -} - -inline void luaL_pushresult(luaL_Buffer_52 *B) { - lua_pushlstring(B->L2, B->ptr, B->nelems); - if (B->ptr != B->b.buffer) - lua_replace(B->L2, -2); /* remove userdata buffer */ -} - -#endif /* SOL_LUA_VERSION == 501 */ - -#endif // SOL_5_X_X_INL -// end of sol/compatibility/5.x.x.inl - -#if defined(__cplusplus) && !defined(SOL_USING_CXX_LUA) -} -#endif - -#endif // SOL_NO_COMPAT - -// end of sol/compatibility.hpp - -// beginning of sol/in_place.hpp - -namespace sol { - - namespace detail { - struct in_place_of {}; - template <std::size_t I> - struct in_place_of_i {}; - template <typename T> - struct in_place_of_t {}; - } // detail - - struct in_place_tag { struct init {}; constexpr in_place_tag(init) {} in_place_tag() = delete; }; - constexpr inline in_place_tag in_place(detail::in_place_of) { return in_place_tag(in_place_tag::init()); } - template <typename T> - constexpr inline in_place_tag in_place(detail::in_place_of_t<T>) { return in_place_tag(in_place_tag::init()); } - template <std::size_t I> - constexpr inline in_place_tag in_place(detail::in_place_of_i<I>) { return in_place_tag(in_place_tag::init()); } - - using in_place_t = in_place_tag(&)(detail::in_place_of); - template <typename T> - using in_place_type_t = in_place_tag(&)(detail::in_place_of_t<T>); - template <std::size_t I> - using in_place_index_t = in_place_tag(&)(detail::in_place_of_i<I>); - -} // sol - -// end of sol/in_place.hpp - -#if defined(SOL_USE_BOOST) -#include <boost/optional.hpp> -#else -// beginning of sol/optional_implementation.hpp - -# ifndef SOL_OPTIONAL_IMPLEMENTATION_HPP -# define SOL_OPTIONAL_IMPLEMENTATION_HPP - -# include <utility> -# include <type_traits> -# include <initializer_list> -# include <cassert> -# include <functional> -# include <string> -# include <stdexcept> -#ifdef SOL_NO_EXCEPTIONS -#include <cstdlib> -#endif // Exceptions - -# define TR2_OPTIONAL_REQUIRES(...) typename ::std::enable_if<__VA_ARGS__::value, bool>::type = false - -# if defined __GNUC__ // NOTE: GNUC is also defined for Clang -# if (__GNUC__ >= 5) -# define TR2_OPTIONAL_GCC_5_0_AND_HIGHER___ -# define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ -# elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8) -# define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ -# elif (__GNUC__ > 4) -# define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ -# endif -# -# if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 7) -# define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ -# elif (__GNUC__ > 4) -# define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ -# endif -# -# if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ >= 1) -# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9) -# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# elif (__GNUC__ > 4) -# define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# endif -# endif -# -# if defined __clang_major__ -# if (__clang_major__ == 3 && __clang_minor__ >= 5) -# define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ -# elif (__clang_major__ > 3) -# define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ -# endif -# if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ -# define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ -# elif (__clang_major__ == 3 && __clang_minor__ == 4 && __clang_patchlevel__ >= 2) -# define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ -# endif -# endif -# -# if defined _MSC_VER -# if (_MSC_VER >= 1900) -# define TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ -# endif -# endif - -# if defined __clang__ -# if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9) -# define OPTIONAL_HAS_THIS_RVALUE_REFS 1 -# else -# define OPTIONAL_HAS_THIS_RVALUE_REFS 0 -# endif -# elif defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# define OPTIONAL_HAS_THIS_RVALUE_REFS 1 -# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ -# define OPTIONAL_HAS_THIS_RVALUE_REFS 1 -# else -# define OPTIONAL_HAS_THIS_RVALUE_REFS 0 -# endif - -# if defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ -# define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 1 -# define OPTIONAL_CONSTEXPR_INIT_LIST constexpr -# else -# define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 0 -# define OPTIONAL_CONSTEXPR_INIT_LIST -# endif - -# if defined(TR2_OPTIONAL_MSVC_2015_AND_HIGHER___) || (defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ && (defined __cplusplus) && (__cplusplus != 201103L)) -# define OPTIONAL_HAS_MOVE_ACCESSORS 1 -# else -# define OPTIONAL_HAS_MOVE_ACCESSORS 0 -# endif - -# // In C++11 constexpr implies const, so we need to make non-const members also non-constexpr -# if defined(TR2_OPTIONAL_MSVC_2015_AND_HIGHER___) || ((defined __cplusplus) && (__cplusplus == 201103L)) -# define OPTIONAL_MUTABLE_CONSTEXPR -# else -# define OPTIONAL_MUTABLE_CONSTEXPR constexpr -# endif - -# if defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ -#pragma warning( push ) -#pragma warning( disable : 4814 ) -#endif - -namespace sol { - - // BEGIN workaround for missing is_trivially_destructible -# if defined TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ - // leave it: it is already there -# elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ - // leave it: it is already there -# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ - // leave it: it is already there -# elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS - // leave it: the user doesn't want it -# else - template <typename T> - using is_trivially_destructible = ::std::has_trivial_destructor<T>; -# endif - // END workaround for missing is_trivially_destructible - -# if (defined TR2_OPTIONAL_GCC_4_7_AND_HIGHER___) - // leave it; our metafunctions are already defined. -# elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ - // leave it; our metafunctions are already defined. -# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ - // leave it: it is already there -# elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS - // leave it: the user doesn't want it -# else - - template <class T> - struct is_nothrow_move_constructible - { - constexpr static bool value = ::std::is_nothrow_constructible<T, T&&>::value; - }; - - template <class T, class U> - struct is_assignable - { - template <class X, class Y> - constexpr static bool has_assign(...) { return false; } - - template <class X, class Y, size_t S = sizeof((::std::declval<X>() = ::std::declval<Y>(), true)) > - // the comma operator is necessary for the cases where operator= returns void - constexpr static bool has_assign(bool) { return true; } - - constexpr static bool value = has_assign<T, U>(true); - }; - - template <class T> - struct is_nothrow_move_assignable - { - template <class X, bool has_any_move_assign> - struct has_nothrow_move_assign { - constexpr static bool value = false; - }; - - template <class X> - struct has_nothrow_move_assign<X, true> { - constexpr static bool value = noexcept(::std::declval<X&>() = ::std::declval<X&&>()); - }; - - constexpr static bool value = has_nothrow_move_assign<T, is_assignable<T&, T&&>::value>::value; - }; - // end workaround - -# endif - - template <class T> class optional; - - // 20.5.5, optional for lvalue reference types - template <class T> class optional<T&>; - - // workaround: std utility functions aren't constexpr yet - template <class T> inline constexpr T&& constexpr_forward(typename ::std::remove_reference<T>::type& t) noexcept - { - return static_cast<T&&>(t); - } - - template <class T> inline constexpr T&& constexpr_forward(typename ::std::remove_reference<T>::type&& t) noexcept - { - static_assert(!::std::is_lvalue_reference<T>::value, "!!"); - return static_cast<T&&>(t); - } - - template <class T> inline constexpr typename ::std::remove_reference<T>::type&& constexpr_move(T&& t) noexcept - { - return static_cast<typename ::std::remove_reference<T>::type&&>(t); - } - -#if defined NDEBUG -# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR) -#else -# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) ((CHECK) ? (EXPR) : ([]{assert(!#CHECK);}(), (EXPR))) -#endif - - namespace detail_ - { - - // static_addressof: a constexpr version of addressof - template <typename T> - struct has_overloaded_addressof - { - template <class X> - constexpr static bool has_overload(...) { return false; } - - template <class X, size_t S = sizeof(::std::declval<X&>().operator&()) > - constexpr static bool has_overload(bool) { return true; } - - constexpr static bool value = has_overload<T>(true); - }; - - template <typename T, TR2_OPTIONAL_REQUIRES(!has_overloaded_addressof<T>)> - constexpr T* static_addressof(T& ref) - { - return &ref; - } - - template <typename T, TR2_OPTIONAL_REQUIRES(has_overloaded_addressof<T>)> - T* static_addressof(T& ref) - { - return ::std::addressof(ref); - } - - // the call to convert<A>(b) has return type A and converts b to type A iff b decltype(b) is implicitly convertible to A - template <class U> - constexpr U convert(U v) { return v; } - - } // namespace detail_ - - constexpr struct trivial_init_t {} trivial_init{}; - - // 20.5.7, Disengaged state indicator - struct nullopt_t - { - struct init {}; - constexpr explicit nullopt_t(init) {} - }; - constexpr nullopt_t nullopt{ nullopt_t::init() }; - - // 20.5.8, class bad_optional_access - class bad_optional_access : public ::std::logic_error { - public: - explicit bad_optional_access(const ::std::string& what_arg) : ::std::logic_error{ what_arg } {} - explicit bad_optional_access(const char* what_arg) : ::std::logic_error{ what_arg } {} - }; - - template <class T> - struct alignas(T) optional_base { - char storage_[sizeof(T)]; - bool init_; - - constexpr optional_base() noexcept : storage_(), init_(false) {}; - - explicit optional_base(const T& v) : storage_(), init_(true) { - new (&storage())T(v); - } - - explicit optional_base(T&& v) : storage_(), init_(true) { - new (&storage())T(constexpr_move(v)); - } - - template <class... Args> explicit optional_base(in_place_t, Args&&... args) - : init_(true), storage_() { - new (&storage())T(constexpr_forward<Args>(args)...); - } - - template <class U, class... Args, TR2_OPTIONAL_REQUIRES(::std::is_constructible<T, ::std::initializer_list<U>>)> - explicit optional_base(in_place_t, ::std::initializer_list<U> il, Args&&... args) - : init_(true), storage_() { - new (&storage())T(il, constexpr_forward<Args>(args)...); - } -#if defined __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif - T& storage() { - return *reinterpret_cast<T*>(&storage_[0]); - } - - constexpr const T& storage() const { - return *reinterpret_cast<T const*>(&storage_[0]); - } -#if defined __GNUC__ -#pragma GCC diagnostic pop -#endif - - ~optional_base() { if (init_) { storage().T::~T(); } } - }; - -#if defined __GNUC__ && !defined TR2_OPTIONAL_GCC_5_0_AND_HIGHER___ - // Sorry, GCC 4.x; you're just a piece of shit - template <typename T> - using constexpr_optional_base = optional_base<T>; -#else - template <class T> - struct alignas(T) constexpr_optional_base { - char storage_[sizeof(T)]; - bool init_; - constexpr constexpr_optional_base() noexcept : storage_(), init_(false) {} - - explicit constexpr constexpr_optional_base(const T& v) : storage_(), init_(true) { - new (&storage())T(v); - } - - explicit constexpr constexpr_optional_base(T&& v) : storage_(), init_(true) { - new (&storage())T(constexpr_move(v)); - } - - template <class... Args> explicit constexpr constexpr_optional_base(in_place_t, Args&&... args) - : init_(true), storage_() { - new (&storage())T(constexpr_forward<Args>(args)...); - } - - template <class U, class... Args, TR2_OPTIONAL_REQUIRES(::std::is_constructible<T, ::std::initializer_list<U>>)> - OPTIONAL_CONSTEXPR_INIT_LIST explicit constexpr_optional_base(in_place_t, ::std::initializer_list<U> il, Args&&... args) - : init_(true), storage_() { - new (&storage())T(il, constexpr_forward<Args>(args)...); - } - -#if defined __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif - T& storage() { - return (*reinterpret_cast<T*>(&storage_[0])); - } - - constexpr const T& storage() const { - return (*reinterpret_cast<T const*>(&storage_[0])); - } -#if defined __GNUC__ -#pragma GCC diagnostic pop -#endif - - ~constexpr_optional_base() = default; - }; -#endif - - template <class T> - using OptionalBase = typename ::std::conditional< - ::std::is_trivially_destructible<T>::value, - constexpr_optional_base<typename ::std::remove_const<T>::type>, - optional_base<typename ::std::remove_const<T>::type> - >::type; - - template <class T> - class optional : private OptionalBase<T> - { - static_assert(!::std::is_same<typename ::std::decay<T>::type, nullopt_t>::value, "bad T"); - static_assert(!::std::is_same<typename ::std::decay<T>::type, in_place_t>::value, "bad T"); - - constexpr bool initialized() const noexcept { return OptionalBase<T>::init_; } - typename ::std::remove_const<T>::type* dataptr() { return ::std::addressof(OptionalBase<T>::storage()); } - constexpr const T* dataptr() const { return detail_::static_addressof(OptionalBase<T>::storage()); } - -# if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 - constexpr const T& contained_val() const& { return OptionalBase<T>::storage(); } -# if OPTIONAL_HAS_MOVE_ACCESSORS == 1 - OPTIONAL_MUTABLE_CONSTEXPR T&& contained_val() && { return ::std::move(OptionalBase<T>::storage()); } - OPTIONAL_MUTABLE_CONSTEXPR T& contained_val() & { return OptionalBase<T>::storage(); } -# else - T& contained_val() & { return OptionalBase<T>::storage(); } - T&& contained_val() && { return ::std::move(OptionalBase<T>::storage()); } -# endif -# else - constexpr const T& contained_val() const { return OptionalBase<T>::storage(); } - T& contained_val() { return OptionalBase<T>::storage(); } -# endif - - void clear() noexcept { - if (initialized()) dataptr()->T::~T(); - OptionalBase<T>::init_ = false; - } - - template <class... Args> - void initialize(Args&&... args) noexcept(noexcept(T(::std::forward<Args>(args)...))) - { - assert(!OptionalBase<T>::init_); - ::new (static_cast<void*>(dataptr())) T(::std::forward<Args>(args)...); - OptionalBase<T>::init_ = true; - } - - template <class U, class... Args> - void initialize(::std::initializer_list<U> il, Args&&... args) noexcept(noexcept(T(il, ::std::forward<Args>(args)...))) - { - assert(!OptionalBase<T>::init_); - ::new (static_cast<void*>(dataptr())) T(il, ::std::forward<Args>(args)...); - OptionalBase<T>::init_ = true; - } - - public: - typedef T value_type; - - // 20.5.5.1, constructors - constexpr optional() noexcept : OptionalBase<T>() {}; - constexpr optional(nullopt_t) noexcept : OptionalBase<T>() {}; - - optional(const optional& rhs) - : OptionalBase<T>() - { - if (rhs.initialized()) { - ::new (static_cast<void*>(dataptr())) T(*rhs); - OptionalBase<T>::init_ = true; - } - } - - optional(const optional<T&>& rhs) : optional() - { - if (rhs) { - ::new (static_cast<void*>(dataptr())) T(*rhs); - OptionalBase<T>::init_ = true; - } - } - - optional(optional&& rhs) noexcept(::std::is_nothrow_move_constructible<T>::value) - : OptionalBase<T>() - { - if (rhs.initialized()) { - ::new (static_cast<void*>(dataptr())) T(::std::move(*rhs)); - OptionalBase<T>::init_ = true; - } - } - - constexpr optional(const T& v) : OptionalBase<T>(v) {} - - constexpr optional(T&& v) : OptionalBase<T>(constexpr_move(v)) {} - - template <class... Args> - explicit constexpr optional(in_place_t, Args&&... args) - : OptionalBase<T>(in_place, constexpr_forward<Args>(args)...) {} - - template <class U, class... Args, TR2_OPTIONAL_REQUIRES(::std::is_constructible<T, ::std::initializer_list<U>>)> - OPTIONAL_CONSTEXPR_INIT_LIST explicit optional(in_place_t, ::std::initializer_list<U> il, Args&&... args) - : OptionalBase<T>(in_place, il, constexpr_forward<Args>(args)...) {} - - // 20.5.4.2, Destructor - ~optional() = default; - - // 20.5.4.3, assignment - optional& operator=(nullopt_t) noexcept - { - clear(); - return *this; - } - - optional& operator=(const optional& rhs) - { - if (initialized() == true && rhs.initialized() == false) clear(); - else if (initialized() == false && rhs.initialized() == true) initialize(*rhs); - else if (initialized() == true && rhs.initialized() == true) contained_val() = *rhs; - return *this; - } - - optional& operator=(optional&& rhs) - noexcept(::std::is_nothrow_move_assignable<T>::value && ::std::is_nothrow_move_constructible<T>::value) - { - if (initialized() == true && rhs.initialized() == false) clear(); - else if (initialized() == false && rhs.initialized() == true) initialize(::std::move(*rhs)); - else if (initialized() == true && rhs.initialized() == true) contained_val() = ::std::move(*rhs); - return *this; - } - - template <class U> - auto operator=(U&& v) - -> typename ::std::enable_if - < - ::std::is_same<typename ::std::decay<U>::type, T>::value, - optional& - >::type - { - if (initialized()) { contained_val() = ::std::forward<U>(v); } - else { initialize(::std::forward<U>(v)); } - return *this; - } - - template <class... Args> - void emplace(Args&&... args) - { - clear(); - initialize(::std::forward<Args>(args)...); - } - - template <class U, class... Args> - void emplace(::std::initializer_list<U> il, Args&&... args) - { - clear(); - initialize<U, Args...>(il, ::std::forward<Args>(args)...); - } - - // 20.5.4.4, Swap - void swap(optional<T>& rhs) noexcept(::std::is_nothrow_move_constructible<T>::value && noexcept(swap(::std::declval<T&>(), ::std::declval<T&>()))) - { - if (initialized() == true && rhs.initialized() == false) { rhs.initialize(::std::move(**this)); clear(); } - else if (initialized() == false && rhs.initialized() == true) { initialize(::std::move(*rhs)); rhs.clear(); } - else if (initialized() == true && rhs.initialized() == true) { using ::std::swap; swap(**this, *rhs); } - } - - // 20.5.4.5, Observers - - explicit constexpr operator bool() const noexcept { return initialized(); } - - constexpr T const* operator ->() const { - return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), dataptr()); - } - -# if OPTIONAL_HAS_MOVE_ACCESSORS == 1 - - OPTIONAL_MUTABLE_CONSTEXPR T* operator ->() { - assert(initialized()); - return dataptr(); - } - - constexpr T const& operator *() const& { - return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val()); - } - - OPTIONAL_MUTABLE_CONSTEXPR T& operator *() & { - assert(initialized()); - return contained_val(); - } - - OPTIONAL_MUTABLE_CONSTEXPR T&& operator *() && { - assert(initialized()); - return constexpr_move(contained_val()); - } - - constexpr T const& value() const& { - return initialized() ? - contained_val() -#ifdef SOL_NO_EXCEPTIONS - // we can't abort here - // because there's no constexpr abort - : *(T*)nullptr; -#else - : (throw bad_optional_access("bad optional access"), contained_val()); -#endif - } - - OPTIONAL_MUTABLE_CONSTEXPR T& value() & { - return initialized() ? - contained_val() -#ifdef SOL_NO_EXCEPTIONS - : *(T*)nullptr; -#else - : (throw bad_optional_access("bad optional access"), contained_val()); -#endif - } - - OPTIONAL_MUTABLE_CONSTEXPR T&& value() && { - return initialized() ? - contained_val() -#ifdef SOL_NO_EXCEPTIONS - // we can't abort here - // because there's no constexpr abort - : std::move(*(T*)nullptr); -#else - : (throw bad_optional_access("bad optional access"), contained_val()); -#endif - } - -# else - - T* operator ->() { - assert(initialized()); - return dataptr(); - } - - constexpr T const& operator *() const { - return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val()); - } - -
<TRUNCATED>