// Copyright (c) 2016-2021 Antony Polukhin // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_PFR_DETAIL_SEQUENCE_TUPLE_HPP #define BOOST_PFR_DETAIL_SEQUENCE_TUPLE_HPP #pragma once #include #include #include // metaprogramming stuff #include // std::size_t ///////////////////// Tuple that holds its values in the supplied order namespace boost { namespace pfr { namespace detail { namespace sequence_tuple { template struct base_from_member { T value; }; template struct tuple_base; template struct tuple_base< std::index_sequence, Tail... > : base_from_member... { static constexpr std::size_t size_v = sizeof...(I); // We do not use `noexcept` in the following functions, because if user forget to put one then clang will issue an error: // "error: exception specification of explicitly defaulted default constructor does not match the calculated one". constexpr tuple_base() = default; constexpr tuple_base(tuple_base&&) = default; constexpr tuple_base(const tuple_base&) = default; constexpr tuple_base(Tail... v) noexcept : base_from_member{ v }... {} }; template <> struct tuple_base > { static constexpr std::size_t size_v = 0; }; template constexpr T& get_impl(base_from_member& t) noexcept { return t.value; } template constexpr const T& get_impl(const base_from_member& t) noexcept { return t.value; } template constexpr volatile T& get_impl(volatile base_from_member& t) noexcept { return t.value; } template constexpr const volatile T& get_impl(const volatile base_from_member& t) noexcept { return t.value; } template constexpr T&& get_impl(base_from_member&& t) noexcept { return std::forward(t.value); } template struct tuple: tuple_base< detail::index_sequence_for, Values...> { using tuple_base< detail::index_sequence_for, Values... >::tuple_base; }; template constexpr decltype(auto) get(tuple& t) noexcept { static_assert(N < tuple::size_v, "====================> Boost.PFR: Tuple index out of bounds"); return sequence_tuple::get_impl(t); } template constexpr decltype(auto) get(const tuple& t) noexcept { static_assert(N < tuple::size_v, "====================> Boost.PFR: Tuple index out of bounds"); return sequence_tuple::get_impl(t); } template constexpr decltype(auto) get(const volatile tuple& t) noexcept { static_assert(N < tuple::size_v, "====================> Boost.PFR: Tuple index out of bounds"); return sequence_tuple::get_impl(t); } template constexpr decltype(auto) get(volatile tuple& t) noexcept { static_assert(N < tuple::size_v, "====================> Boost.PFR: Tuple index out of bounds"); return sequence_tuple::get_impl(t); } template constexpr decltype(auto) get(tuple&& t) noexcept { static_assert(N < tuple::size_v, "====================> Boost.PFR: Tuple index out of bounds"); return sequence_tuple::get_impl(std::move(t)); } template using tuple_element = std::remove_reference< decltype( ::boost::pfr::detail::sequence_tuple::get( std::declval() ) ) >; }}}} // namespace boost::pfr::detail::sequence_tuple #endif // BOOST_PFR_CORE_HPP