Skip to content

Commit 22464a2

Browse files
Add more detail to documentation
1 parent 848b2dd commit 22464a2

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,28 @@ This invokation, has a tuple t: `std::tuple<int, char, bool>` and then transform
102102
103103
`mlib::transform`'s implementation looks like this:
104104
```C++
105-
template<typename... Ts, std::size_t... indexes>
106-
constexpr auto transform_helper(std::tuple<Ts...>& t, auto& lambda, std::index_sequence<indexes...>& i_s)
107-
{
108-
return std::make_tuple(f(std::get<indexes>(t))...);
105+
template <typename... Ts, std::size_t... indexes>
106+
constexpr auto transform_helper(std::tuple<Ts...> t, auto lambda,
107+
std::index_sequence<indexes...> i_s) {
108+
return std::make_tuple(lambda(std::get<indexes>(t))...);
109109
}
110110
111-
template<typename T, typename... Ts>
112-
constexpr auto transform(std::tuple<T, Ts...>& t, auto& lambda)
113-
{
114-
return transform_helper(t, lambda, std::make_index_sequence<sizeof...(Ts) + 1>{});
111+
template <typename T, typename... Ts>
112+
constexpr auto transform(std::tuple<T, Ts...> t, auto lambda) {
113+
return transform_helper(t, lambda,
114+
std::make_index_sequence<sizeof...(Ts)>{});
115115
}
116116
```
117117
It is a very simple implementation, and `mlib::transform` is a great tool.
118118

119+
The benchmark is as [follows](https://godbolt.org/z/T73f7GhbP):
120+
```
121+
-------------------------------------------------------
122+
Benchmark Time CPU Iterations
123+
-------------------------------------------------------
124+
BM_Transform 307 ns 173 ns 3620400
125+
```
126+
119127
----------------------------------------------------------------------------------------------------------------------------------------------------------
120128
### `mlib::fixed_string`.
121129
`mlib::transform` is a string that can be used at compile time, so the size needs to be known at compile time and needs to be passed as an [NTTP](https://stackoverflow.com/questions/70924025/c20-nttp-specialization) or it can be infered by the `constexpr` constructor. Here is how you would have a compile time string, using `fixed_string`:

0 commit comments

Comments
 (0)