Loading...
Searching...
No Matches
indices.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_COMMON_INDICES_HH
#define DUNE_COMMON_INDICES_HH
#include <cstddef>
#include <stdexcept>
#include <type_traits>
#include <utility>
namespace Dune
{
template<std::size_t i>
using index_constant = std::integral_constant<std::size_t, i>;
namespace Indices
{
inline constexpr index_constant< 0> _0 = {};
inline constexpr index_constant< 1> _1 = {};
inline constexpr index_constant< 2> _2 = {};
inline constexpr index_constant< 3> _3 = {};
inline constexpr index_constant< 4> _4 = {};
inline constexpr index_constant< 5> _5 = {};
inline constexpr index_constant< 6> _6 = {};
inline constexpr index_constant< 7> _7 = {};
inline constexpr index_constant< 8> _8 = {};
inline constexpr index_constant< 9> _9 = {};
inline constexpr index_constant<10> _10 = {};
inline constexpr index_constant<11> _11 = {};
inline constexpr index_constant<12> _12 = {};
inline constexpr index_constant<13> _13 = {};
inline constexpr index_constant<14> _14 = {};
inline constexpr index_constant<15> _15 = {};
inline constexpr index_constant<16> _16 = {};
inline constexpr index_constant<17> _17 = {};
inline constexpr index_constant<18> _18 = {};
inline constexpr index_constant<19> _19 = {};
} // namespace Indices
template<class F, class I, I... i>
decltype(auto) constexpr unpackIntegerSequence(F&& f, [[maybe_unused]] std::integer_sequence<I, i...> sequence)
{
return f(std::integral_constant<I, i>()...);
}
namespace Indices { inline namespace Literals
{
namespace Impl
{
// convert a single character into an unsigned integer
constexpr unsigned char2digit (const char c)
{
if (c >= '0' && c <= '9')
return unsigned(c) - unsigned('0');
else {
throw std::invalid_argument("Character is not a digit.");
return 0u;
}
}
// convert a sequence of character digits into an unsigned integer
template <class T, char... digits>
constexpr T chars2number ()
{
const char arr[] = {digits...};
T result = 0;
T power = 1;
const T base = 10;
const int N = sizeof...(digits);
for (int i = 0; i < N; ++i) {
char c = arr[N - 1 - i];
result+= char2digit(c) * power;
power *= base;
}
return result;
}
} //namespace Impl
template <char... digits>
constexpr auto operator""_ic()
{
return std::integral_constant<std::size_t, Impl::chars2number<std::size_t,digits...>()>{};
}
template <char... digits>
constexpr auto operator""_uc()
{
return std::integral_constant<unsigned, Impl::chars2number<unsigned,digits...>()>{};
}
template <char... digits>
constexpr auto operator""_sc()
{
return std::integral_constant<int, Impl::chars2number<int,digits...>()>{};
}
template <class T, T value>
constexpr auto operator- (std::integral_constant<T,value>)
{
return std::integral_constant<std::make_signed_t<T>, -value>{};
}
}} //namespace Indices::Literals
} //namespace Dune
#endif // DUNE_COMMON_INDICES_HH
Dune::Indices::_16
constexpr index_constant< 16 > _16
Compile time index with value 16.
Definition indices.hh:100
Dune::Indices::_15
constexpr index_constant< 15 > _15
Compile time index with value 15.
Definition indices.hh:97
Dune::Indices::_8
constexpr index_constant< 8 > _8
Compile time index with value 8.
Definition indices.hh:76
Dune::Indices::_7
constexpr index_constant< 7 > _7
Compile time index with value 7.
Definition indices.hh:73
Dune::Indices::_0
constexpr index_constant< 0 > _0
Compile time index with value 0.
Definition indices.hh:52
Dune::Indices::_9
constexpr index_constant< 9 > _9
Compile time index with value 9.
Definition indices.hh:79
Dune::Indices::_14
constexpr index_constant< 14 > _14
Compile time index with value 14.
Definition indices.hh:94
Dune::Indices::_1
constexpr index_constant< 1 > _1
Compile time index with value 1.
Definition indices.hh:55
Dune::Indices::_3
constexpr index_constant< 3 > _3
Compile time index with value 3.
Definition indices.hh:61
Dune::Indices::_12
constexpr index_constant< 12 > _12
Compile time index with value 12.
Definition indices.hh:88
Dune::unpackIntegerSequence
decltype(auto) constexpr unpackIntegerSequence(F &&f, std::integer_sequence< I, i... > sequence)
Unpack an std::integer_sequence<I,i...> to std::integral_constant<I,i>...
Definition indices.hh:124
Dune::Indices::Literals::operator-
constexpr auto operator-(std::integral_constant< T, value >)
Negation operator for integral constants.
Definition indices.hh:209
Dune::Indices::_11
constexpr index_constant< 11 > _11
Compile time index with value 11.
Definition indices.hh:85
Dune::Indices::_18
constexpr index_constant< 18 > _18
Compile time index with value 18.
Definition indices.hh:106
Dune::Indices::_13
constexpr index_constant< 13 > _13
Compile time index with value 13.
Definition indices.hh:91
Dune::Indices::_5
constexpr index_constant< 5 > _5
Compile time index with value 5.
Definition indices.hh:67
Dune::Indices::_17
constexpr index_constant< 17 > _17
Compile time index with value 17.
Definition indices.hh:103
Dune::Indices::_10
constexpr index_constant< 10 > _10
Compile time index with value 10.
Definition indices.hh:82
Dune::Indices::_2
constexpr index_constant< 2 > _2
Compile time index with value 2.
Definition indices.hh:58
Dune::index_constant
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition indices.hh:29
Dune::Indices::_19
constexpr index_constant< 19 > _19
Compile time index with value 19.
Definition indices.hh:109
Dune::Indices::_6
constexpr index_constant< 6 > _6
Compile time index with value 6.
Definition indices.hh:70
Dune::Indices::_4
constexpr index_constant< 4 > _4
Compile time index with value 4.
Definition indices.hh:64
Dune
Dune namespace
Definition alignedallocator.hh:13
Dune::power
constexpr Base power(Base m, Exponent p)
Power method for integer exponents.
Definition math.hh:75
Dune::Indices
Namespace with predefined compile time indices for the range [0,19].
Definition indices.hh:50
Dune::Indices::Literals
Definition indices.hh:131