forked from boostorg/pfr
-
Notifications
You must be signed in to change notification settings - Fork 13
/
tuple_size.hpp
50 lines (40 loc) · 1.52 KB
/
tuple_size.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2016-2017 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_FLAT_TUPLE_SIZE_HPP
#define BOOST_PFR_FLAT_TUPLE_SIZE_HPP
#pragma once
#include <boost/pfr/detail/config.hpp>
#include <utility> // metaprogramming stuff
#include <boost/pfr/detail/sequence_tuple.hpp>
#include <boost/pfr/detail/core14.hpp>
//for flat_tuple_size, see below
#ifdef _MSC_VER
constexpr std::size_t size_v = 4;
#endif
namespace boost { namespace pfr {
/// \brief Has a static const member variable `value` that contains fields count in a \flattening{flattened} T.
///
/// \note (Giperion): On MSVC not working properly (compiler not support correctly)
/// \b Example:
/// \code
/// std::array<int, boost::pfr::flat_tuple_size<my_structure>::value > a;
/// \endcode
#ifdef _MSC_VER
template <class T>
using flat_tuple_size = boost::pfr::detail::size_t_<size_v>;
#else
template <class T>
using flat_tuple_size = boost::pfr::detail::size_t_<decltype(boost::pfr::detail::tie_as_flat_tuple(std::declval<T&>()))::size_v>;
#endif
/// \brief `flat_tuple_size_v` is a template variable that contains fields count in a \flattening{flattened} T.
///
/// \b Example:
/// \code
/// std::array<int, boost::pfr::flat_tuple_size_v<my_structure> > a;
/// \endcode
template <class T>
constexpr std::size_t flat_tuple_size_v = flat_tuple_size<T>::value;
}} // namespace boost::pfr
#endif // BOOST_PFR_FLAT_TUPLE_SIZE_HPP