• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DNKpp / Simple-Utility / 6500581756

12 Oct 2023 08:26PM UTC coverage: 86.926% (-12.8%) from 99.712%
6500581756

Pull #71

github

web-flow
Merge 1fb43c509 into e4166ac5d
Pull Request #71: graph namespace

284 of 284 new or added lines in 17 files covered. (100.0%)

625 of 719 relevant lines covered (86.93%)

154.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.67
/include/Simple-Utility/functional/Tuple.hpp
1
//          Copyright Dominic Koepke 2019 - 2023.
2
// Distributed under the Boost Software License, Version 1.0.
3
//    (See accompanying file LICENSE_1_0.txt or copy at
4
//          https://www.boost.org/LICENSE_1_0.txt)
5

6
#ifndef SL_UTILITY_FUNCTIONAL_TUPLE_HPP
7
#define SL_UTILITY_FUNCTIONAL_TUPLE_HPP
8

9
#pragma once
10

11
#include "Simple-Utility/concepts/utility.hpp"
12
#include "Simple-Utility/functional/Transform.hpp"
13
#include "Simple-Utility/tuple/General.hpp"
14

15
#include <tuple>
16
#include <utility>
17

18
namespace sl::functional::tuple
19
{
20
        /**
21
         * \defgroup GROUP_FUNCTIONAL_TUPLE tuple
22
         * \ingroup GROUP_FUNCTIONAL GROUP_TUPLE_UTILITY
23
         * \brief Contains several tuple related ``Transform`` definitions and the ``Apply`` closure template.
24
         * 
25
         * \{
26
         */
27

28
        /**
29
         * \brief Functional object which retrieves an object of a specific type from a tuple-like argument.
30
         * \tparam T The type to be retrieved.
31
         */
32
        template <class T>
33
        inline constexpr auto get = envelop<Transform>(
34
                []<class Tuple>(Tuple&& v) -> decltype(auto)requires concepts::tuple<std::remove_cvref_t<Tuple>>
6✔
35
                {
36
                        using std::get;
37
                        return get<T>(std::forward<Tuple>(v));
3✔
38
                });
39

40
        /**
41
         * \brief Functional object which retrieves an object at a specific index from a tuple-like argument.
42
         * \tparam index The index of type to be retrieved.
43
         */
44
        template <std::size_t index>
45
        inline constexpr auto get_at = envelop<Transform>(
46
                []<class Tuple>(Tuple&& v) -> decltype(auto)requires concepts::tuple<std::remove_cvref_t<Tuple>>
8✔
47
                {
48
                        using std::get;
49
                        return get<index>(std::forward<Tuple>(v));
5✔
50
                });
51
}
52

53
namespace sl::functional::tuple::detail
54
{
55
        // workaround
56
        // as of MSVC version 19.32.31328.0 the following workaround became necessary.
57
        template <class... Args, class Tuple>
58
                requires concepts::tuple<std::remove_cvref_t<Tuple>>
59
        constexpr std::tuple<Args...> reduce(Tuple&& tuple)
×
60
        {
61
                return {tuple::get<Args>(std::forward<Tuple>(tuple))...};
×
62
        }
63

64
        // workaround
65
        // as of MSVC version 19.32.31328.0 the following workaround became necessary.
66
        template <class... Tuples>
67
                requires (... && concepts::tuple<std::remove_cvref_t<Tuples>>)
68
        constexpr auto concat(Tuples&&... tuples)
×
69
        {
70
                return std::tuple_cat(std::forward<Tuples>(tuples)...);
×
71
        }
72
}
73

74
namespace sl::functional::tuple
75
{
76
        /**
77
         * \brief Reduces (or permutes) the components of a tuple and returns a them as new tuple.
78
         * \tparam Args The component types of the returned tuple.
79
         * \remark The source and target tuples must consist of unique types.
80
         */
81
        template <class... Args>
82
                requires concepts::unique_types<Args...>
83
        inline constexpr auto reduce = envelop<Transform>(
84
                []<class Tuple>(Tuple&& t)
×
85
                        requires concepts::tuple<std::remove_cvref_t<Tuple>>
86
                {
87
                        return detail::reduce<Args...>(std::forward<Tuple>(t));
×
88
                });
89

90
        /**
91
         * \brief Combines all elements from each given tuple into one tuple.
92
         */
93
        inline constexpr auto concat = envelop<Transform>(
94
                []<class... Tuples>(Tuples&&... tuples)
×
95
                        requires (... && concepts::tuple<std::remove_cvref_t<Tuples>>)
96
                {
97
                        return detail::concat(std::forward<Tuples>(tuples)...);
×
98
                });
99

100
        /**
101
         * \brief Combines all given lvalue references into one tuple.
102
         */
103
        inline constexpr auto tie = envelop<Transform>(
104
                [](auto&... args) { return std::tie(args...); });
16✔
105

106
        /**
107
         * \brief Constructs an object with elements from the source tuple as constructor arguments.
108
         */
109
        template <class To>
110
        inline constexpr auto make_from = envelop<Transform>(
111
                []<class Tuple>(Tuple&& t) noexcept(noexcept(std::make_from_tuple<To>(std::forward<Tuple>(t))))
1✔
112
                        requires concepts::tuple<std::remove_cvref_t<Tuple>>
113
                {
114
                        // Due to a bug in gcc-10, we must check this requirement in two steps
115
                        static_assert(
116
                                requires { { std::make_from_tuple<To>(std::forward<Tuple>(t)) }; },
117
                                "The object is not constructible with the elements of the given tuple.");
118
                        static_assert(
119
                                std::same_as<To, decltype(std::make_from_tuple<To>(std::declval<Tuple>()))>,
120
                                "The object is not constructible with the elements of the given tuple.");
121

122
                        return std::make_from_tuple<To>(std::forward<Tuple>(t));
1✔
123
                });
124

125
        /**
126
         * \}
127
         */
128
}
129

130
namespace sl::functional
131
{
132
        /**
133
        * \brief Stores a functional and forwards elements from provided tuples as params on invocation.
134
        * \ingroup GROUP_FUNCTIONAL
135
        */
136
        template <function Fn>
137
        using Apply = BasicClosure<Fn, NodiscardApplyPolicy, PipeOperator>;
138
}
139

140
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc