Dune Core Modules (2.9.0)

filledarray.hh
Go to the documentation of this file.
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 (C) DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5 
6 #ifndef DUNE_COMMON_FILLED_ARRAY_HH
7 #define DUNE_COMMON_FILLED_ARRAY_HH
8 
13 #include <array>
14 #include <cstddef>
15 
16 namespace Dune
17 {
24 
32  template<std::size_t n, class T>
33  constexpr std::array<T, n> filledArray(const T& t)
34  {
35  std::array<T, n> arr{};
36  // this is constexpr in c++17, `arr.fill(t)` is not
37  for(auto &el : arr)
38  el = t;
39  return arr;
40  }
41 
44 } // end namespace Dune
45 
46 #endif // DUNE_COMMON_FILLED_ARRAY_HH
constexpr std::array< T, n > filledArray(const T &t)
Return an array filled with the provided value.
Definition: filledarray.hh:33
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 9, 22:29, 2024)