DUNE PDELab (git)

containerconstructiontraits.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_COMMON_STD_IMPL_CONTAINER_CONSTRUCTION_TRAITS_HH
6#define DUNE_COMMON_STD_IMPL_CONTAINER_CONSTRUCTION_TRAITS_HH
7
8#include <array>
9#include <cassert>
10#include <cstddef>
11
12namespace Dune::Std {
13namespace Impl {
14
20template <class Container>
21struct ContainerConstructionTraits
22{
23 using container_type = Container;
24 using value_type = typename container_type::value_type;
25
26 static constexpr container_type construct (std::size_t size)
27 {
28 return container_type(size);
29 }
30
31 static constexpr container_type construct (std::size_t size, value_type value)
32 {
33 return container_type(size, value);
34 }
35};
36
37template <class Value, std::size_t N>
38struct ContainerConstructionTraits<std::array<Value,N>>
39{
40 using container_type = std::array<Value,N>;
41 using value_type = typename container_type::value_type;
42
43 static constexpr container_type construct ([[maybe_unused]] std::size_t size)
44 {
45 assert(size <= N);
46 return container_type{};
47 }
48
49 static constexpr container_type construct ([[maybe_unused]] std::size_t size, value_type value)
50 {
51 assert(size <= N);
52 container_type c{};
53 for (auto& c_i : c)
54 c_i = value;
55 return c;
56 }
57};
58
59} // end namespace Impl
60} // end namespace Dune::Std
61
62#endif // DUNE_COMMON_STD_IMPL_CONTAINER_CONSTRUCTION_TRAITS_HH
Namespace for features backported from new C++ standards.
Definition: default_accessor.hh:10
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)