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 51 52 53 54
|
// -*- 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
#include <array>
#include <iostream>
#include <type_traits>
#include <dune/common/filledarray.hh>
struct A {
A(int i) : value(i) {}
int value;
bool operator==(A const& a) const { return value == a.value; }
bool operator!=(A const& a) const { return value != a.value; }
};
int main() {
int status = 0;
auto test1 = Dune::filledArray<2>(2.0);
static_assert(std::is_same<decltype(test1), std::array<double, 2> >::value,
"Wrong result type for Dune::filledArray()");
if(test1[0] != 2.0 || test1[1] != 2.0)
{
std::cerr << "Dune::filledArray() produces wrong value" << std::endl;
status = 1;
}
#ifdef __cpp_lib_array_constexpr
std::cout << "The result of Dune::filledArray() is constexpr" << std::endl;
constexpr auto test2 = Dune::filledArray<2>(2);
(void)test2;
#else // !__cpp_lib_array_constexpr
std::cout << "Not checking whether Dune::filledArray() is constexpr\n"
<< "since the library does not declare std::array as constexpr\n"
<< "(__cpp_lib_array_constexpr is not defined)." << std::endl;
#endif // !__cpp_lib_array_constexpr
static_assert(not std::is_default_constructible_v<A>);
auto test3 = Dune::filledArray<2>(A(7));
static_assert(std::is_same<decltype(test3), std::array<A, 2> >::value,
"Wrong result type for Dune::filledArray()");
if(test3[0] != A(7) || test3[1] != A(7))
{
std::cerr << "Dune::filledArray() produces wrong value" << std::endl;
status = 1;
}
return status;
}
|