Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:24

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 // Project include(s)
0010 #include "detray/utils/tuple_helpers.hpp"
0011 
0012 // System include(s)
0013 #include <cassert>
0014 #include <string>
0015 #include <tuple>
0016 #include <type_traits>
0017 
0018 // GoogleTest include(s).
0019 #include <gtest/gtest.h>
0020 
0021 GTEST_TEST(detray_utils, tuple_helpers) {
0022   using namespace detray;
0023 
0024   // std::tuple test
0025   auto s_tuple =
0026       detail::make_tuple<std::tuple>(2.0f, -3L, std::string("std::tuple"), 4UL);
0027   static_assert(
0028       std::is_same_v<std::tuple<float, long, std::string, unsigned long>,
0029                      decltype(s_tuple)>,
0030       "detail::make_tuple failed for std::tuple");
0031 
0032   static_assert(std::is_same_v<detail::tuple_element_t<2, decltype(s_tuple)>,
0033                                std::string>,
0034                 "detail::tuple_element retrieval failed for std::tuple");
0035 
0036   const auto s_tuple_size = detail::tuple_size_v<decltype(s_tuple)>;
0037   EXPECT_EQ(s_tuple_size, 4UL);
0038 
0039   EXPECT_FLOAT_EQ(detail::get<0>(s_tuple), 2.0f);
0040   EXPECT_EQ(detail::get<1>(s_tuple), -3L);
0041   EXPECT_EQ(detail::get<2>(s_tuple), std::string("std::tuple"));
0042   EXPECT_EQ(detail::get<3>(s_tuple), 4UL);
0043   EXPECT_FLOAT_EQ(detail::get<float>(s_tuple), 2.0f);
0044   EXPECT_EQ(detail::get<long>(s_tuple), -3L);
0045   EXPECT_EQ(detail::get<std::string>(s_tuple), std::string("std::tuple"));
0046   EXPECT_EQ(detail::get<unsigned long>(s_tuple), 4UL);
0047 
0048   // dtuple test
0049   auto d_tuple = detail::make_tuple<dtuple>(1.0f, 2UL, std::string("dtuple"));
0050   static_assert(std::is_same_v<dtuple<float, unsigned long, std::string>,
0051                                decltype(d_tuple)>,
0052                 "detail::make_tuple failed for dtuple");
0053 
0054   static_assert(std::is_same_v<detail::tuple_element_t<1, decltype(d_tuple)>,
0055                                unsigned long>,
0056                 "detail::tuple_element retrieval failed for dtuple");
0057 
0058   const auto d_tuple_size = detail::tuple_size_v<decltype(d_tuple)>;
0059   EXPECT_EQ(d_tuple_size, 3UL);
0060 
0061   EXPECT_FLOAT_EQ(detail::get<0>(d_tuple), 1.0f);
0062   EXPECT_EQ(detail::get<1>(d_tuple), 2UL);
0063   EXPECT_EQ(detail::get<2>(d_tuple), std::string("dtuple"));
0064   EXPECT_FLOAT_EQ(detail::get<float>(d_tuple), 1.0f);
0065   EXPECT_EQ(detail::get<unsigned long>(d_tuple), 2UL);
0066   EXPECT_EQ(detail::get<std::string>(d_tuple), std::string("dtuple"));
0067 
0068   // Check type concatenation
0069   static_assert(
0070       std::same_as<
0071           detail::tuple_cat_t<std::tuple<int, double>, std::tuple<float>,
0072                               std::tuple<>, std::tuple<char, bool, double>>,
0073           std::tuple<int, double, float, char, bool, double>>);
0074 
0075   static_assert(
0076       std::same_as<detail::tuple_cat_t<dtuple<int, double>, dtuple<float>,
0077                                        dtuple<>, dtuple<char, bool, double>>,
0078                    dtuple<int, double, float, char, bool, double>>);
0079 
0080   // Permutation check
0081   static_assert(detail::is_permutation_v<dtuple<>, dtuple<>>);
0082   static_assert(detail::is_permutation_v<dtuple<int>, dtuple<int>>);
0083   static_assert(!detail::is_permutation_v<dtuple<int>, dtuple<int, int>>);
0084   static_assert(detail::is_permutation_v<dtuple<int, float, double>,
0085                                          dtuple<double, int, float>>);
0086   static_assert(!detail::is_permutation_v<dtuple<int, float, double>,
0087                                           dtuple<char, int, float>>);
0088   static_assert(!detail::is_permutation_v<dtuple<int, float, double>,
0089                                           dtuple<int, int, double, float>>);
0090 
0091   // Check unique element tuple type
0092   static_assert(std::same_as<detail::unique_t<dtuple<>>, dtuple<>>);
0093   static_assert(std::same_as<detail::unique_t<dtuple<int>>, dtuple<int>>);
0094   static_assert(std::same_as<detail::unique_t<dtuple<int, int>>, dtuple<int>>);
0095   static_assert(
0096       std::same_as<detail::unique_t<dtuple<int, int, int>>, dtuple<int>>);
0097   static_assert(std::same_as<detail::unique_t<dtuple<int, float, int, int>>,
0098                              dtuple<int, float>>);
0099   static_assert(
0100       std::same_as<detail::unique_t<dtuple<int, float, int, int, double>>,
0101                    dtuple<double, float, int>>);
0102 }