Skip to content
Snippets Groups Projects
Commit e1fbb9eb authored by namark's avatar namark
Browse files

Convenience meta function for transforming tuples,

with barely a test.
parent 703a75b6
No related branches found
No related tags found
No related merge requests found
...@@ -4,5 +4,7 @@ ...@@ -4,5 +4,7 @@
#include "tuple_utils/meta_bind.hpp" #include "tuple_utils/meta_bind.hpp"
#include "tuple_utils/meta_find.hpp" #include "tuple_utils/meta_find.hpp"
#include "tuple_utils/meta_flatten.hpp" #include "tuple_utils/meta_flatten.hpp"
#include "tuple_utils/meta_transform.hpp"
#include "tuple_utils/pend.hpp" #include "tuple_utils/pend.hpp"
#include "tuple_utils/subtuple.hpp" #include "tuple_utils/subtuple.hpp"
#ifndef SIMPLE_SUPPORT_TUPLE_UTILS_META_TRANSFORM_HPP
#define SIMPLE_SUPPORT_TUPLE_UTILS_META_TRANSFORM_HPP
#include "meta_flatten.hpp"
namespace simple::support
{
template <template<typename...> typename transformer>
struct meta_transform_tuple_wrapper
{
template <typename... Ts>
struct op
{
using type = std::tuple<transformer<Ts...>>;
};
};
template <typename Tuple, template <typename...> typename Operator>
using transform_t = flatten_t
<
Tuple,
meta_transform_tuple_wrapper<Operator>::template op
>;
} // namespace simple::support
#endif /* end of include guard */
// TODO: need a test file per header and include the header first, to detect missing includes // TODO: need a test file per header and include the header first, to detect missing includes
#include "simple/support/tuple_utils.hpp"
#include "simple/support/function_utils.hpp"
#include <cassert> #include <cassert>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <array> #include <array>
#include "simple/support/tuple_utils.hpp"
#include "simple/support/function_utils.hpp"
using namespace simple::support; using namespace simple::support;
using namespace std::literals; using namespace std::literals;
...@@ -522,6 +523,15 @@ void MetaFlatten() ...@@ -522,6 +523,15 @@ void MetaFlatten()
>); >);
} }
void MetaTransform()
{
static_assert(std::is_same_v<
transform_t<std::tuple<long, int, short, signed char>,
std::make_unsigned_t>,
std::tuple<unsigned long, unsigned, unsigned short, unsigned char>
>);
}
int main() int main()
{ {
ApplyFor(); ApplyFor();
...@@ -534,5 +544,6 @@ int main() ...@@ -534,5 +544,6 @@ int main()
Pend(); Pend();
MetaFind(); MetaFind();
MetaFlatten(); MetaFlatten();
MetaTransform();
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment