|
||||
File indexing completed on 2025-01-18 09:43:38
0001 // Copyright (c) 2023 Bela Schaum, X-Ryl669, Denis Mikhailov. 0002 // 0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying 0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0005 0006 0007 // Initial implementation by Bela Schaum, https://github.com/schaumb 0008 // The way to make it union and UB free by X-Ryl669, https://github.com/X-Ryl669 0009 // 0010 0011 #ifndef BOOST_PFR_CORE_NAME_HPP 0012 #define BOOST_PFR_CORE_NAME_HPP 0013 #pragma once 0014 0015 #include <boost/pfr/detail/config.hpp> 0016 0017 #include <boost/pfr/detail/core_name.hpp> 0018 0019 #include <boost/pfr/detail/sequence_tuple.hpp> 0020 #include <boost/pfr/detail/stdarray.hpp> 0021 #include <boost/pfr/detail/make_integer_sequence.hpp> 0022 0023 #include <cstddef> // for std::size_t 0024 0025 #include <boost/pfr/tuple_size.hpp> 0026 0027 /// \file boost/pfr/core_name.hpp 0028 /// Contains functions \forcedlink{get_name} and \forcedlink{names_as_array} to know which names each field of any \aggregate has. 0029 /// 0030 /// \fnrefl for details. 0031 /// 0032 /// \b Synopsis: 0033 0034 namespace boost { namespace pfr { 0035 0036 /// \brief Returns name of a field with index `I` in \aggregate `T`. 0037 /// 0038 /// \b Example: 0039 /// \code 0040 /// struct my_struct { int i, short s; }; 0041 /// 0042 /// assert(boost::pfr::get_name<0, my_struct>() == "i"); 0043 /// assert(boost::pfr::get_name<1, my_struct>() == "s"); 0044 /// \endcode 0045 template <std::size_t I, class T> 0046 constexpr 0047 #ifdef BOOST_PFR_DOXYGEN_INVOKED 0048 std::string_view 0049 #else 0050 auto 0051 #endif 0052 get_name() noexcept { 0053 return detail::get_name<T, I>(); 0054 } 0055 0056 // FIXME: implement this 0057 // template<class U, class T> 0058 // constexpr auto get_name() noexcept { 0059 // return detail::sequence_tuple::get_by_type_impl<U>( detail::tie_as_names_tuple<T>() ); 0060 // } 0061 0062 /// \brief Creates a `std::array` from names of fields of an \aggregate `T`. 0063 /// 0064 /// \b Example: 0065 /// \code 0066 /// struct my_struct { int i, short s; }; 0067 /// std::array<std::string_view, 2> a = boost::pfr::names_as_array<my_struct>(); 0068 /// assert(a[0] == "i"); 0069 /// \endcode 0070 template <class T> 0071 constexpr 0072 #ifdef BOOST_PFR_DOXYGEN_INVOKED 0073 std::array<std::string_view, boost::pfr::tuple_size_v<T>> 0074 #else 0075 auto 0076 #endif 0077 names_as_array() noexcept { 0078 return detail::make_stdarray_from_tietuple( 0079 detail::tie_as_names_tuple<T>(), 0080 detail::make_index_sequence< tuple_size_v<T> >(), 0081 1L 0082 ); 0083 } 0084 0085 }} // namespace boost::pfr 0086 0087 #endif // BOOST_PFR_CORE_NAME_HPP 0088
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |