type_list related tests added to metabench

This commit is contained in:
Mateusz Pusz
2019-05-28 14:33:08 +02:00
parent c3d896e661
commit cec78ec8cb
15 changed files with 1422 additions and 1 deletions

View File

@@ -39,4 +39,7 @@ endif()
enable_testing()
add_custom_target(metabench)
add_subdirectory(ratio)
add_subdirectory(list)

View File

@@ -0,0 +1,54 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Mateusz Pusz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
add_metabench_test(metabench.data.list.type_list.concepts_all "all concepts" type_list_concepts_all.cpp.erb "[3, 6, 9, 12, 15]")
add_metabench_test(metabench.data.list.type_list.concepts_iface "concepts in interface" type_list_concepts_iface.cpp.erb "[3, 6, 9, 12, 15]")
add_metabench_test(metabench.data.list.type_list.concepts_no "no concepts" type_list_concepts_no.cpp.erb "[3, 6, 9, 12, 15]")
metabench_add_chart(metabench.chart.list.concepts
TITLE "Sorting a list of size N"
SUBTITLE "(smaller is better)"
DATASETS
metabench.data.list.type_list.concepts_all
metabench.data.list.type_list.concepts_iface
metabench.data.list.type_list.concepts_no
)
add_metabench_test(metabench.data.list.type_list.conditional_std "std::conditional" type_list_conditional_std.cpp.erb "[3, 6, 9, 12, 15]")
add_metabench_test(metabench.data.list.type_list.conditional_alias "alias conditional" type_list_conditional_alias.cpp.erb "[3, 6, 9, 12, 15]")
add_metabench_test(metabench.data.list.type_list.conditional_alias_hard "alias conditional hard" type_list_conditional_alias_hard.cpp.erb "[3, 6, 9, 12, 15]")
metabench_add_chart(metabench.chart.list.conditional
TITLE "Sorting a list of size N"
SUBTITLE "(smaller is better)"
DATASETS
metabench.data.list.type_list.conditional_std
metabench.data.list.type_list.conditional_alias
metabench.data.list.type_list.conditional_alias_hard
)
add_custom_target(metabench.chart.list
DEPENDS
metabench.chart.list.concepts
metabench.chart.list.conditional
)
add_dependencies(metabench metabench.chart.list)

View File

@@ -0,0 +1,33 @@
#include "type_list_concepts_all.h"
template<int UniqueValue>
using dim_id = std::integral_constant<int, UniqueValue>;
template<typename D1, typename D2>
using dim_id_less = std::bool_constant<D1::value < D2::value>;
template<typename... Es>
struct dimension;
<% (1..10).each do |k| %>
struct test<%= k %> {
<% (1..n).each do |i| %>
using <%= "dim#{i}" %> = dimension<<%=
xs = ((1)..(i)).map { |j| "dim_id<#{k*n+i+j}>" }
rng = Random.new(i)
xs.shuffle(random: rng).join(', ')
%>>;
#if defined(METABENCH)
using <%= "result#{i}" %> = units::type_list_sort_t<<%= "dim#{i}" %>, dim_id_less>;
#endif
<% end %>
};
<% end %>
int main()
{
}

View File

@@ -0,0 +1,185 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include <type_traits>
namespace units {
namespace detail {
template<bool>
struct conditional {
template<typename T, typename F>
using type = F;
};
template<>
struct conditional<true> {
template<typename T, typename F>
using type = T;
};
template<bool B, typename T, typename F>
using conditional_t = conditional<B>::template type<T, F>;
}
namespace detail {
template<typename T>
inline constexpr bool is_type_list = false;
template<template<typename...> typename T, typename... Types>
inline constexpr bool is_type_list<T<Types...>> = true;
} // namespace detail
template<typename T>
concept bool TypeList = detail::is_type_list<T>;
// push_front
template<TypeList List, typename... Types>
struct type_list_push_front;
template<template<typename...> typename List, typename... OldTypes, typename... NewTypes>
struct type_list_push_front<List<OldTypes...>, NewTypes...> {
using type = List<NewTypes..., OldTypes...>;
};
template<TypeList List, typename... Types>
using type_list_push_front_t = type_list_push_front<List, Types...>::type;
// push_back
template<TypeList List, typename... Types>
struct type_list_push_back;
template<template<typename...> typename List, typename... OldTypes, typename... NewTypes>
struct type_list_push_back<List<OldTypes...>, NewTypes...> {
using type = List<OldTypes..., NewTypes...>;
};
template<TypeList List, typename... Types>
using type_list_push_back_t = type_list_push_back<List, Types...>::type;
// split
namespace detail {
template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename... Types>
struct split_impl;
template<template<typename...> typename List, std::size_t Idx, std::size_t N>
struct split_impl<List, Idx, N> {
using first_list = List<>;
using second_list = List<>;
};
template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename T, typename... Rest>
struct split_impl<List, Idx, N, T, Rest...> : split_impl<List, Idx + 1, N, Rest...> {
using base = split_impl<List, Idx + 1, N, Rest...>;
using base_first = base::first_list;
using base_second = base::second_list;
using first_list = detail::conditional_t<Idx < N, type_list_push_front_t<base_first, T>, base_first>;
using second_list = detail::conditional_t<Idx < N, base_second, type_list_push_front_t<base_second, T>>;
};
} // namespace detail
template<TypeList List, std::size_t N>
struct type_list_split;
template<template<typename...> typename List, std::size_t N, typename... Types>
struct type_list_split<List<Types...>, N> {
static_assert(N <= sizeof...(Types), "Invalid index provided");
using split = detail::split_impl<List, 0, N, Types...>;
using first_list = split::first_list;
using second_list = split::second_list;
};
// split_half
template<TypeList List>
struct type_list_split_half;
template<template<typename...> typename List, typename... Types>
struct type_list_split_half<List<Types...>> : type_list_split<List<Types...>, (sizeof...(Types) + 1) / 2> {
};
// merge_sorted
template<TypeList SortedList1, TypeList SortedList2, template<typename, typename> typename Pred>
struct type_list_merge_sorted;
template<TypeList SortedList1, TypeList SortedList2, template<typename, typename> typename Pred>
using type_list_merge_sorted_t = type_list_merge_sorted<SortedList1, SortedList2, Pred>::type;
template<template<typename...> typename List, typename... Lhs, template<typename, typename> typename Pred>
struct type_list_merge_sorted<List<Lhs...>, List<>, Pred> {
using type = List<Lhs...>;
};
template<template<typename...> typename List, typename... Rhs, template<typename, typename> typename Pred>
struct type_list_merge_sorted<List<>, List<Rhs...>, Pred> {
using type = List<Rhs...>;
};
template<template<typename...> typename List, typename Lhs1, typename... LhsRest, typename Rhs1, typename... RhsRest,
template<typename, typename> typename Pred>
struct type_list_merge_sorted<List<Lhs1, LhsRest...>, List<Rhs1, RhsRest...>, Pred> {
using type = detail::conditional_t<
Pred<Lhs1, Rhs1>::value,
type_list_push_front_t<type_list_merge_sorted_t<List<LhsRest...>, List<Rhs1, RhsRest...>, Pred>, Lhs1>,
type_list_push_front_t<type_list_merge_sorted_t<List<Lhs1, LhsRest...>, List<RhsRest...>, Pred>, Rhs1>>;
};
// sort
template<TypeList List, template<typename, typename> typename Pred>
struct type_list_sort;
template<template<typename...> typename List, template<typename, typename> typename Pred>
struct type_list_sort<List<>, Pred> {
using type = List<>;
};
template<template<typename...> typename List, typename T, template<typename, typename> typename Pred>
struct type_list_sort<List<T>, Pred> {
using type = List<T>;
};
template<template<typename...> typename List, typename... Types, template<typename, typename> typename Pred>
struct type_list_sort<List<Types...>, Pred> {
using types = List<Types...>;
using split = type_list_split_half<List<Types...>>;
using left = type_list_sort<typename split::first_list, Pred>::type;
using right = type_list_sort<typename split::second_list, Pred>::type;
using type = type_list_merge_sorted_t<left, right, Pred>;
};
template<TypeList List, template<typename, typename> typename Pred>
using type_list_sort_t = type_list_sort<List, Pred>::type;
} // namespace units

View File

@@ -0,0 +1,33 @@
#include "type_list_concepts_iface.h"
template<int UniqueValue>
using dim_id = std::integral_constant<int, UniqueValue>;
template<typename D1, typename D2>
using dim_id_less = std::bool_constant<D1::value < D2::value>;
template<typename... Es>
struct dimension;
<% (1..10).each do |k| %>
struct test<%= k %> {
<% (1..n).each do |i| %>
using <%= "dim#{i}" %> = dimension<<%=
xs = ((1)..(i)).map { |j| "dim_id<#{k*n+i+j}>" }
rng = Random.new(i)
xs.shuffle(random: rng).join(', ')
%>>;
#if defined(METABENCH)
using <%= "result#{i}" %> = units::type_list_sort<<%= "dim#{i}" %>, dim_id_less>;
#endif
<% end %>
};
<% end %>
int main()
{
}

View File

@@ -0,0 +1,204 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include <type_traits>
namespace units {
namespace detail {
template<bool>
struct conditional {
template<typename T, typename F>
using type = F;
};
template<>
struct conditional<true> {
template<typename T, typename F>
using type = T;
};
}
template<bool B, typename T, typename F>
using conditional = detail::conditional<B>::template type<T, F>;
namespace detail {
template<typename T>
inline constexpr bool is_type_list = false;
template<template<typename...> typename T, typename... Types>
inline constexpr bool is_type_list<T<Types...>> = true;
} // namespace detail
template<typename T>
concept bool TypeList = detail::is_type_list<T>;
// push_front
namespace detail {
template<typename List, typename... Types>
struct type_list_push_front_impl;
template<template<typename...> typename List, typename... OldTypes, typename... NewTypes>
struct type_list_push_front_impl<List<OldTypes...>, NewTypes...> {
using type = List<NewTypes..., OldTypes...>;
};
}
template<TypeList List, typename... Types>
using type_list_push_front = detail::type_list_push_front_impl<List, Types...>::type;
// push_back
namespace detail {
template<typename List, typename... Types>
struct type_list_push_back_impl;
template<template<typename...> typename List, typename... OldTypes, typename... NewTypes>
struct type_list_push_back_impl<List<OldTypes...>, NewTypes...> {
using type = List<OldTypes..., NewTypes...>;
};
}
template<TypeList List, typename... Types>
using type_list_push_back = detail::type_list_push_back_impl<List, Types...>::type;
// split
namespace detail {
template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename... Types>
struct split_impl;
template<template<typename...> typename List, std::size_t Idx, std::size_t N>
struct split_impl<List, Idx, N> {
using first_list = List<>;
using second_list = List<>;
};
template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename T, typename... Rest>
struct split_impl<List, Idx, N, T, Rest...> : split_impl<List, Idx + 1, N, Rest...> {
using base = split_impl<List, Idx + 1, N, Rest...>;
using first_list = units::conditional<Idx < N,
typename type_list_push_front_impl<typename base::first_list, T>::type,
typename base::first_list>;
using second_list = units::conditional<Idx < N,
typename base::second_list,
typename type_list_push_front_impl<typename base::second_list, T>::type>;
};
} // namespace detail
template<TypeList List, std::size_t N>
struct type_list_split;
template<template<typename...> typename List, std::size_t N, typename... Types>
struct type_list_split<List<Types...>, N> {
static_assert(N <= sizeof...(Types), "Invalid index provided");
using split = detail::split_impl<List, 0, N, Types...>;
using first_list = split::first_list;
using second_list = split::second_list;
};
// split_half
template<TypeList List>
struct type_list_split_half;
template<template<typename...> typename List, typename... Types>
struct type_list_split_half<List<Types...>> : type_list_split<List<Types...>, (sizeof...(Types) + 1) / 2> {
};
// merge_sorted
namespace detail {
template<typename SortedList1, typename SortedList2, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl;
template<template<typename...> typename List, typename... Lhs, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<Lhs...>, List<>, Pred> {
using type = List<Lhs...>;
};
template<template<typename...> typename List, typename... Rhs, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<>, List<Rhs...>, Pred> {
using type = List<Rhs...>;
};
template<template<typename...> typename List, typename Lhs1, typename... LhsRest, typename Rhs1, typename... RhsRest,
template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<Lhs1, LhsRest...>, List<Rhs1, RhsRest...>, Pred> {
using type = units::conditional<
Pred<Lhs1, Rhs1>::value,
typename type_list_push_front_impl<typename type_list_merge_sorted_impl<List<LhsRest...>, List<Rhs1, RhsRest...>, Pred>::type, Lhs1>::type,
typename type_list_push_front_impl<typename type_list_merge_sorted_impl<List<Lhs1, LhsRest...>, List<RhsRest...>, Pred>::type, Rhs1>::type>;
};
}
template<TypeList SortedList1, typename SortedList2, template<typename, typename> typename Pred>
using type_list_merge_sorted = detail::type_list_merge_sorted_impl<SortedList1, SortedList2, Pred>::type;
// sort
namespace detail {
template<typename List, template<typename, typename> typename Pred>
struct type_list_sort_impl;
template<template<typename...> typename List, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<>, Pred> {
using type = List<>;
};
template<template<typename...> typename List, typename T, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<T>, Pred> {
using type = List<T>;
};
template<template<typename...> typename List, typename... Types, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<Types...>, Pred> {
using types = List<Types...>;
using split = type_list_split_half<List<Types...>>;
using left = type_list_sort_impl<typename split::first_list, Pred>::type;
using right = type_list_sort_impl<typename split::second_list, Pred>::type;
using type = type_list_merge_sorted_impl<left, right, Pred>::type;
};
}
template<TypeList List, template<typename, typename> typename Pred>
using type_list_sort = detail::type_list_sort_impl<List, Pred>::type;
} // namespace units

View File

@@ -0,0 +1,33 @@
#include "type_list_concepts_no.h"
template<int UniqueValue>
using dim_id = std::integral_constant<int, UniqueValue>;
template<typename D1, typename D2>
using dim_id_less = std::bool_constant<D1::value < D2::value>;
template<typename... Es>
struct dimension;
<% (1..10).each do |k| %>
struct test<%= k %> {
<% (1..n).each do |i| %>
using <%= "dim#{i}" %> = dimension<<%=
xs = ((1)..(i)).map { |j| "dim_id<#{k*n+i+j}>" }
rng = Random.new(i)
xs.shuffle(random: rng).join(', ')
%>>;
#if defined(METABENCH)
using <%= "result#{i}" %> = units::type_list_sort<<%= "dim#{i}" %>, dim_id_less>;
#endif
<% end %>
};
<% end %>
int main()
{
}

View File

@@ -0,0 +1,191 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include <type_traits>
namespace units {
namespace detail {
template<bool>
struct conditional {
template<typename T, typename F>
using type = F;
};
template<>
struct conditional<true> {
template<typename T, typename F>
using type = T;
};
}
template<bool B, typename T, typename F>
using conditional = detail::conditional<B>::template type<T, F>;
// push_front
namespace detail {
template<typename List, typename... Types>
struct type_list_push_front_impl;
template<template<typename...> typename List, typename... OldTypes, typename... NewTypes>
struct type_list_push_front_impl<List<OldTypes...>, NewTypes...> {
using type = List<NewTypes..., OldTypes...>;
};
}
template<typename List, typename... Types>
using type_list_push_front = detail::type_list_push_front_impl<List, Types...>::type;
// push_back
namespace detail {
template<typename List, typename... Types>
struct type_list_push_back_impl;
template<template<typename...> typename List, typename... OldTypes, typename... NewTypes>
struct type_list_push_back_impl<List<OldTypes...>, NewTypes...> {
using type = List<OldTypes..., NewTypes...>;
};
}
template<typename List, typename... Types>
using type_list_push_back = detail::type_list_push_back_impl<List, Types...>::type;
// split
namespace detail {
template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename... Types>
struct split_impl;
template<template<typename...> typename List, std::size_t Idx, std::size_t N>
struct split_impl<List, Idx, N> {
using first_list = List<>;
using second_list = List<>;
};
template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename T, typename... Rest>
struct split_impl<List, Idx, N, T, Rest...> : split_impl<List, Idx + 1, N, Rest...> {
using base = split_impl<List, Idx + 1, N, Rest...>;
using first_list = units::conditional<Idx < N,
typename type_list_push_front_impl<typename base::first_list, T>::type,
typename base::first_list>;
using second_list = units::conditional<Idx < N,
typename base::second_list,
typename type_list_push_front_impl<typename base::second_list, T>::type>;
};
} // namespace detail
template<typename List, std::size_t N>
struct type_list_split;
template<template<typename...> typename List, std::size_t N, typename... Types>
struct type_list_split<List<Types...>, N> {
static_assert(N <= sizeof...(Types), "Invalid index provided");
using split = detail::split_impl<List, 0, N, Types...>;
using first_list = split::first_list;
using second_list = split::second_list;
};
// split_half
template<typename List>
struct type_list_split_half;
template<template<typename...> typename List, typename... Types>
struct type_list_split_half<List<Types...>> : type_list_split<List<Types...>, (sizeof...(Types) + 1) / 2> {
};
// merge_sorted
namespace detail {
template<typename SortedList1, typename SortedList2, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl;
template<template<typename...> typename List, typename... Lhs, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<Lhs...>, List<>, Pred> {
using type = List<Lhs...>;
};
template<template<typename...> typename List, typename... Rhs, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<>, List<Rhs...>, Pred> {
using type = List<Rhs...>;
};
template<template<typename...> typename List, typename Lhs1, typename... LhsRest, typename Rhs1, typename... RhsRest,
template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<Lhs1, LhsRest...>, List<Rhs1, RhsRest...>, Pred> {
using type = units::conditional<
Pred<Lhs1, Rhs1>::value,
typename type_list_push_front_impl<typename type_list_merge_sorted_impl<List<LhsRest...>, List<Rhs1, RhsRest...>, Pred>::type, Lhs1>::type,
typename type_list_push_front_impl<typename type_list_merge_sorted_impl<List<Lhs1, LhsRest...>, List<RhsRest...>, Pred>::type, Rhs1>::type>;
};
}
template<typename SortedList1, typename SortedList2, template<typename, typename> typename Pred>
using type_list_merge_sorted = detail::type_list_merge_sorted_impl<SortedList1, SortedList2, Pred>::type;
// sort
namespace detail {
template<typename List, template<typename, typename> typename Pred>
struct type_list_sort_impl;
template<template<typename...> typename List, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<>, Pred> {
using type = List<>;
};
template<template<typename...> typename List, typename T, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<T>, Pred> {
using type = List<T>;
};
template<template<typename...> typename List, typename... Types, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<Types...>, Pred> {
using types = List<Types...>;
using split = type_list_split_half<List<Types...>>;
using left = type_list_sort_impl<typename split::first_list, Pred>::type;
using right = type_list_sort_impl<typename split::second_list, Pred>::type;
using type = type_list_merge_sorted_impl<left, right, Pred>::type;
};
}
template<typename List, template<typename, typename> typename Pred>
using type_list_sort = detail::type_list_sort_impl<List, Pred>::type;
} // namespace units

View File

@@ -0,0 +1,33 @@
#include "type_list_conditional_alias.h"
template<int UniqueValue>
using dim_id = std::integral_constant<int, UniqueValue>;
template<typename D1, typename D2>
using dim_id_less = std::bool_constant<D1::value < D2::value>;
template<typename... Es>
struct dimension;
<% (1..10).each do |k| %>
struct test<%= k %> {
<% (1..n).each do |i| %>
using <%= "dim#{i}" %> = dimension<<%=
xs = ((1)..(i)).map { |j| "dim_id<#{k*n+i+j}>" }
rng = Random.new(i)
xs.shuffle(random: rng).join(', ')
%>>;
#if defined(METABENCH)
using <%= "result#{i}" %> = units::type_list_sort<<%= "dim#{i}" %>, dim_id_less>;
#endif
<% end %>
};
<% end %>
int main()
{
}

View File

@@ -0,0 +1,204 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include <type_traits>
namespace units {
namespace detail {
template<bool>
struct conditional {
template<typename T, typename F>
using type = F;
};
template<>
struct conditional<true> {
template<typename T, typename F>
using type = T;
};
}
template<bool B, typename T, typename F>
using conditional = detail::conditional<B>::template type<T, F>;
namespace detail {
template<typename T>
inline constexpr bool is_type_list = false;
template<template<typename...> typename T, typename... Types>
inline constexpr bool is_type_list<T<Types...>> = true;
} // namespace detail
template<typename T>
concept bool TypeList = detail::is_type_list<T>;
// push_front
namespace detail {
template<typename List, typename... Types>
struct type_list_push_front_impl;
template<template<typename...> typename List, typename... OldTypes, typename... NewTypes>
struct type_list_push_front_impl<List<OldTypes...>, NewTypes...> {
using type = List<NewTypes..., OldTypes...>;
};
}
template<TypeList List, typename... Types>
using type_list_push_front = detail::type_list_push_front_impl<List, Types...>::type;
// push_back
namespace detail {
template<typename List, typename... Types>
struct type_list_push_back_impl;
template<template<typename...> typename List, typename... OldTypes, typename... NewTypes>
struct type_list_push_back_impl<List<OldTypes...>, NewTypes...> {
using type = List<OldTypes..., NewTypes...>;
};
}
template<TypeList List, typename... Types>
using type_list_push_back = detail::type_list_push_back_impl<List, Types...>::type;
// split
namespace detail {
template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename... Types>
struct split_impl;
template<template<typename...> typename List, std::size_t Idx, std::size_t N>
struct split_impl<List, Idx, N> {
using first_list = List<>;
using second_list = List<>;
};
template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename T, typename... Rest>
struct split_impl<List, Idx, N, T, Rest...> : split_impl<List, Idx + 1, N, Rest...> {
using base = split_impl<List, Idx + 1, N, Rest...>;
using first_list = units::conditional<Idx < N,
typename type_list_push_front_impl<typename base::first_list, T>::type,
typename base::first_list>;
using second_list = units::conditional<Idx < N,
typename base::second_list,
typename type_list_push_front_impl<typename base::second_list, T>::type>;
};
} // namespace detail
template<TypeList List, std::size_t N>
struct type_list_split;
template<template<typename...> typename List, std::size_t N, typename... Types>
struct type_list_split<List<Types...>, N> {
static_assert(N <= sizeof...(Types), "Invalid index provided");
using split = detail::split_impl<List, 0, N, Types...>;
using first_list = split::first_list;
using second_list = split::second_list;
};
// split_half
template<TypeList List>
struct type_list_split_half;
template<template<typename...> typename List, typename... Types>
struct type_list_split_half<List<Types...>> : type_list_split<List<Types...>, (sizeof...(Types) + 1) / 2> {
};
// merge_sorted
namespace detail {
template<typename SortedList1, typename SortedList2, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl;
template<template<typename...> typename List, typename... Lhs, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<Lhs...>, List<>, Pred> {
using type = List<Lhs...>;
};
template<template<typename...> typename List, typename... Rhs, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<>, List<Rhs...>, Pred> {
using type = List<Rhs...>;
};
template<template<typename...> typename List, typename Lhs1, typename... LhsRest, typename Rhs1, typename... RhsRest,
template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<Lhs1, LhsRest...>, List<Rhs1, RhsRest...>, Pred> {
using type = units::conditional<
Pred<Lhs1, Rhs1>::value,
typename type_list_push_front_impl<typename type_list_merge_sorted_impl<List<LhsRest...>, List<Rhs1, RhsRest...>, Pred>::type, Lhs1>::type,
typename type_list_push_front_impl<typename type_list_merge_sorted_impl<List<Lhs1, LhsRest...>, List<RhsRest...>, Pred>::type, Rhs1>::type>;
};
}
template<TypeList SortedList1, typename SortedList2, template<typename, typename> typename Pred>
using type_list_merge_sorted = detail::type_list_merge_sorted_impl<SortedList1, SortedList2, Pred>::type;
// sort
namespace detail {
template<typename List, template<typename, typename> typename Pred>
struct type_list_sort_impl;
template<template<typename...> typename List, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<>, Pred> {
using type = List<>;
};
template<template<typename...> typename List, typename T, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<T>, Pred> {
using type = List<T>;
};
template<template<typename...> typename List, typename... Types, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<Types...>, Pred> {
using types = List<Types...>;
using split = type_list_split_half<List<Types...>>;
using left = type_list_sort_impl<typename split::first_list, Pred>::type;
using right = type_list_sort_impl<typename split::second_list, Pred>::type;
using type = type_list_merge_sorted_impl<left, right, Pred>::type;
};
}
template<TypeList List, template<typename, typename> typename Pred>
using type_list_sort = detail::type_list_sort_impl<List, Pred>::type;
} // namespace units

View File

@@ -0,0 +1,33 @@
#include "type_list_conditional_alias_hard.h"
template<int UniqueValue>
using dim_id = std::integral_constant<int, UniqueValue>;
template<typename D1, typename D2>
using dim_id_less = std::bool_constant<D1::value < D2::value>;
template<typename... Es>
struct dimension;
<% (1..10).each do |k| %>
struct test<%= k %> {
<% (1..n).each do |i| %>
using <%= "dim#{i}" %> = dimension<<%=
xs = ((1)..(i)).map { |j| "dim_id<#{k*n+i+j}>" }
rng = Random.new(i)
xs.shuffle(random: rng).join(', ')
%>>;
#if defined(METABENCH)
using <%= "result#{i}" %> = units::type_list_sort<<%= "dim#{i}" %>, dim_id_less>;
#endif
<% end %>
};
<% end %>
int main()
{
}

View File

@@ -0,0 +1,197 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include <type_traits>
namespace units {
template<bool>
struct conditional {
template<typename T, typename F>
using type = F;
};
template<>
struct conditional<true> {
template<typename T, typename F>
using type = T;
};
namespace detail {
template<typename T>
inline constexpr bool is_type_list = false;
template<template<typename...> typename T, typename... Types>
inline constexpr bool is_type_list<T<Types...>> = true;
} // namespace detail
template<typename T>
concept bool TypeList = detail::is_type_list<T>;
// push_front
namespace detail {
template<typename List, typename... Types>
struct type_list_push_front_impl;
template<template<typename...> typename List, typename... OldTypes, typename... NewTypes>
struct type_list_push_front_impl<List<OldTypes...>, NewTypes...> {
using type = List<NewTypes..., OldTypes...>;
};
}
template<TypeList List, typename... Types>
using type_list_push_front = detail::type_list_push_front_impl<List, Types...>::type;
// push_back
namespace detail {
template<typename List, typename... Types>
struct type_list_push_back_impl;
template<template<typename...> typename List, typename... OldTypes, typename... NewTypes>
struct type_list_push_back_impl<List<OldTypes...>, NewTypes...> {
using type = List<OldTypes..., NewTypes...>;
};
}
template<TypeList List, typename... Types>
using type_list_push_back = detail::type_list_push_back_impl<List, Types...>::type;
// split
namespace detail {
template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename... Types>
struct split_impl;
template<template<typename...> typename List, std::size_t Idx, std::size_t N>
struct split_impl<List, Idx, N> {
using first_list = List<>;
using second_list = List<>;
};
template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename T, typename... Rest>
struct split_impl<List, Idx, N, T, Rest...> : split_impl<List, Idx + 1, N, Rest...> {
using base = split_impl<List, Idx + 1, N, Rest...>;
using first_list = conditional<Idx < N>::template type<
typename type_list_push_front_impl<typename base::first_list, T>::type,
typename base::first_list>;
using second_list = conditional<Idx < N>::template type<
typename base::second_list,
typename type_list_push_front_impl<typename base::second_list, T>::type>;
};
} // namespace detail
template<TypeList List, std::size_t N>
struct type_list_split;
template<template<typename...> typename List, std::size_t N, typename... Types>
struct type_list_split<List<Types...>, N> {
static_assert(N <= sizeof...(Types), "Invalid index provided");
using split = detail::split_impl<List, 0, N, Types...>;
using first_list = split::first_list;
using second_list = split::second_list;
};
// split_half
template<TypeList List>
struct type_list_split_half;
template<template<typename...> typename List, typename... Types>
struct type_list_split_half<List<Types...>> : type_list_split<List<Types...>, (sizeof...(Types) + 1) / 2> {
};
// merge_sorted
namespace detail {
template<typename SortedList1, typename SortedList2, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl;
template<template<typename...> typename List, typename... Lhs, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<Lhs...>, List<>, Pred> {
using type = List<Lhs...>;
};
template<template<typename...> typename List, typename... Rhs, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<>, List<Rhs...>, Pred> {
using type = List<Rhs...>;
};
template<template<typename...> typename List, typename Lhs1, typename... LhsRest, typename Rhs1, typename... RhsRest,
template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<Lhs1, LhsRest...>, List<Rhs1, RhsRest...>, Pred> {
using type = units::conditional<
Pred<Lhs1, Rhs1>::value>::template type<
typename type_list_push_front_impl<typename type_list_merge_sorted_impl<List<LhsRest...>, List<Rhs1, RhsRest...>, Pred>::type, Lhs1>::type,
typename type_list_push_front_impl<typename type_list_merge_sorted_impl<List<Lhs1, LhsRest...>, List<RhsRest...>, Pred>::type, Rhs1>::type>;
};
}
template<TypeList SortedList1, typename SortedList2, template<typename, typename> typename Pred>
using type_list_merge_sorted = detail::type_list_merge_sorted_impl<SortedList1, SortedList2, Pred>::type;
// sort
namespace detail {
template<typename List, template<typename, typename> typename Pred>
struct type_list_sort_impl;
template<template<typename...> typename List, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<>, Pred> {
using type = List<>;
};
template<template<typename...> typename List, typename T, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<T>, Pred> {
using type = List<T>;
};
template<template<typename...> typename List, typename... Types, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<Types...>, Pred> {
using types = List<Types...>;
using split = type_list_split_half<List<Types...>>;
using left = type_list_sort_impl<typename split::first_list, Pred>::type;
using right = type_list_sort_impl<typename split::second_list, Pred>::type;
using type = type_list_merge_sorted_impl<left, right, Pred>::type;
};
}
template<TypeList List, template<typename, typename> typename Pred>
using type_list_sort = detail::type_list_sort_impl<List, Pred>::type;
} // namespace units

View File

@@ -0,0 +1,33 @@
#include "type_list_conditional_std.h"
template<int UniqueValue>
using dim_id = std::integral_constant<int, UniqueValue>;
template<typename D1, typename D2>
using dim_id_less = std::bool_constant<D1::value < D2::value>;
template<typename... Es>
struct dimension;
<% (1..10).each do |k| %>
struct test<%= k %> {
<% (1..n).each do |i| %>
using <%= "dim#{i}" %> = dimension<<%=
xs = ((1)..(i)).map { |j| "dim_id<#{k*n+i+j}>" }
rng = Random.new(i)
xs.shuffle(random: rng).join(', ')
%>>;
#if defined(METABENCH)
using <%= "result#{i}" %> = units::type_list_sort<<%= "dim#{i}" %>, dim_id_less>;
#endif
<% end %>
};
<% end %>
int main()
{
}

View File

@@ -0,0 +1,185 @@
// The MIT License (MIT)
//
// Copyright (c) 2018 Mateusz Pusz
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include <type_traits>
namespace units {
namespace detail {
template<typename T>
inline constexpr bool is_type_list = false;
template<template<typename...> typename T, typename... Types>
inline constexpr bool is_type_list<T<Types...>> = true;
} // namespace detail
template<typename T>
concept bool TypeList = detail::is_type_list<T>;
// push_front
namespace detail {
template<typename List, typename... Types>
struct type_list_push_front_impl;
template<template<typename...> typename List, typename... OldTypes, typename... NewTypes>
struct type_list_push_front_impl<List<OldTypes...>, NewTypes...> {
using type = List<NewTypes..., OldTypes...>;
};
}
template<TypeList List, typename... Types>
using type_list_push_front = detail::type_list_push_front_impl<List, Types...>::type;
// push_back
namespace detail {
template<typename List, typename... Types>
struct type_list_push_back_impl;
template<template<typename...> typename List, typename... OldTypes, typename... NewTypes>
struct type_list_push_back_impl<List<OldTypes...>, NewTypes...> {
using type = List<OldTypes..., NewTypes...>;
};
}
template<TypeList List, typename... Types>
using type_list_push_back = detail::type_list_push_back_impl<List, Types...>::type;
// split
namespace detail {
template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename... Types>
struct split_impl;
template<template<typename...> typename List, std::size_t Idx, std::size_t N>
struct split_impl<List, Idx, N> {
using first_list = List<>;
using second_list = List<>;
};
template<template<typename...> typename List, std::size_t Idx, std::size_t N, typename T, typename... Rest>
struct split_impl<List, Idx, N, T, Rest...> : split_impl<List, Idx + 1, N, Rest...> {
using base = split_impl<List, Idx + 1, N, Rest...>;
using first_list = std::conditional_t<Idx < N,
typename type_list_push_front_impl<typename base::first_list, T>::type,
typename base::first_list>;
using second_list = std::conditional_t<Idx < N,
typename base::second_list,
typename type_list_push_front_impl<typename base::second_list, T>::type>;
};
} // namespace detail
template<TypeList List, std::size_t N>
struct type_list_split;
template<template<typename...> typename List, std::size_t N, typename... Types>
struct type_list_split<List<Types...>, N> {
static_assert(N <= sizeof...(Types), "Invalid index provided");
using split = detail::split_impl<List, 0, N, Types...>;
using first_list = split::first_list;
using second_list = split::second_list;
};
// split_half
template<TypeList List>
struct type_list_split_half;
template<template<typename...> typename List, typename... Types>
struct type_list_split_half<List<Types...>> : type_list_split<List<Types...>, (sizeof...(Types) + 1) / 2> {
};
// merge_sorted
namespace detail {
template<typename SortedList1, typename SortedList2, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl;
template<template<typename...> typename List, typename... Lhs, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<Lhs...>, List<>, Pred> {
using type = List<Lhs...>;
};
template<template<typename...> typename List, typename... Rhs, template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<>, List<Rhs...>, Pred> {
using type = List<Rhs...>;
};
template<template<typename...> typename List, typename Lhs1, typename... LhsRest, typename Rhs1, typename... RhsRest,
template<typename, typename> typename Pred>
struct type_list_merge_sorted_impl<List<Lhs1, LhsRest...>, List<Rhs1, RhsRest...>, Pred> {
using type = std::conditional_t<
Pred<Lhs1, Rhs1>::value,
typename type_list_push_front_impl<typename type_list_merge_sorted_impl<List<LhsRest...>, List<Rhs1, RhsRest...>, Pred>::type, Lhs1>::type,
typename type_list_push_front_impl<typename type_list_merge_sorted_impl<List<Lhs1, LhsRest...>, List<RhsRest...>, Pred>::type, Rhs1>::type>;
};
}
template<TypeList SortedList1, typename SortedList2, template<typename, typename> typename Pred>
using type_list_merge_sorted = detail::type_list_merge_sorted_impl<SortedList1, SortedList2, Pred>::type;
// sort
namespace detail {
template<typename List, template<typename, typename> typename Pred>
struct type_list_sort_impl;
template<template<typename...> typename List, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<>, Pred> {
using type = List<>;
};
template<template<typename...> typename List, typename T, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<T>, Pred> {
using type = List<T>;
};
template<template<typename...> typename List, typename... Types, template<typename, typename> typename Pred>
struct type_list_sort_impl<List<Types...>, Pred> {
using types = List<Types...>;
using split = type_list_split_half<List<Types...>>;
using left = type_list_sort_impl<typename split::first_list, Pred>::type;
using right = type_list_sort_impl<typename split::second_list, Pred>::type;
using type = type_list_merge_sorted_impl<left, right, Pred>::type;
};
}
template<TypeList List, template<typename, typename> typename Pred>
using type_list_sort = detail::type_list_sort_impl<List, Pred>::type;
} // namespace units

View File

@@ -69,4 +69,4 @@ add_custom_target(metabench.chart.ratio
metabench.chart.ratio.all
)
add_custom_target(metabench DEPENDS metabench.chart.ratio)
add_dependencies(metabench metabench.chart.ratio)