Ideas / Things Made #1
Replies: 16 comments 25 replies
-
I could also add something like this godbolt, where we have a bit of reflection. But bear in mind that this link does not work! |
Beta Was this translation helpful? Give feedback.
-
https://www.godbolt.org/z/GYxbGoKh1, godbolt is where i currently am at. |
Beta Was this translation helpful? Give feedback.
-
make this change to |
Beta Was this translation helpful? Give feedback.
-
Ideas: Meta_struct that has a secret variable |
Beta Was this translation helpful? Give feedback.
-
Add these short two lines of code to template<auto T>
static constexpr auto c_p = constexpr_parameter<T>{}; |
Beta Was this translation helpful? Give feedback.
-
Add this compile time switch statement: godbolt. Here is an example use case constexpr_switch<5, [](case_<0>) {std::cout << "it is 0\n";},
[](case_<5>) {std::cout << "it is not 0\n";},
[](auto) {std::cout << "I don't know what it is!\n";}
> value{};
value(); |
Beta Was this translation helpful? Give feedback.
-
https://www.godbolt.org/z/db8hzKzWd |
Beta Was this translation helpful? Give feedback.
-
I made a constexpr iota, here is the godbolt link godbolt and here is the code: // iota for the mlib library
#include<tuple>
#include<cstddef>
#include<utility>
#include<iostream>
template<auto lambda, typename... Ts>
constexpr auto for_each(std::tuple<Ts...> t)
{
[=] <std::size_t... indexes>(std::index_sequence<indexes...>)
{
(lambda(std::get<indexes>(t)), ...);
}(std::make_index_sequence<sizeof...(Ts)>{});
}
template<auto until>
constexpr auto iota()
{
return []<std::size_t... indexes>(std::index_sequence<indexes...>)
{
return std::make_tuple(indexes...);
}(std::make_index_sequence<until>{});
}
int main()
{
constexpr std::tuple iota_vec = iota<10>();
for_each<[](auto x){std::cout << x << " ";}>(iota_vec);
} |
Beta Was this translation helpful? Give feedback.
-
👋 Welcome!
We’re using Discussions as a place to connect with other members of our community. We hope that you:
build together 💪.
To get started, comment below with an introduction of yourself and tell us about what you do with this community.
Beta Was this translation helpful? Give feedback.
All reactions