Skip to content

Commit

Permalink
✨ add typevector
Browse files Browse the repository at this point in the history
  • Loading branch information
zie87 committed Oct 11, 2023
1 parent ea309f8 commit 99d062f
Show file tree
Hide file tree
Showing 38 changed files with 2,743 additions and 0 deletions.
22 changes: 22 additions & 0 deletions include/zll/meta/types/typevector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#ifndef ZLL_META_TYPE_TYPEVECTOR_HPP
#define ZLL_META_TYPE_TYPEVECTOR_HPP

#include "zll/meta/types/typevector/typevector.hpp"
#include "zll/meta/types/typevector/is_typevector.hpp"

#include "zll/meta/types/typevector/append.hpp"
#include "zll/meta/types/typevector/at.hpp"
#include "zll/meta/types/typevector/contains.hpp"
#include "zll/meta/types/typevector/index_of.hpp"
#include "zll/meta/types/typevector/push.hpp"
#include "zll/meta/types/typevector/remove.hpp"
#include "zll/meta/types/typevector/replace.hpp"
#include "zll/meta/types/typevector/size.hpp"

#endif // ZLL_META_TYPE_TYPEVECTOR_HPP
68 changes: 68 additions & 0 deletions include/zll/meta/types/typevector/append.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#ifndef ZLL_META_TYPES_TYPEVECTOR_APPEND_HPP
#define ZLL_META_TYPES_TYPEVECTOR_APPEND_HPP

#include "zll/meta/types/append.hpp"
#include "zll/meta/types/typevector/typevector.hpp"
#include "zll/meta/types/typevector/is_typevector.hpp"
#include "zll/meta/types/typevector/at.hpp"
#include "zll/meta/types/typevector/push.hpp"
#include "zll/meta/types/typevector/size.hpp"

namespace zll {
namespace meta {

namespace detail {

template <typename VEC_T, typename APPEND_T, zll::uint_fast32_t INDEX_V, zll::uint_fast32_t SIZE_V>
struct typevector_append_helper_impl {
typedef typename push_back<VEC_T, typename at<APPEND_T, INDEX_V>::type>::type temp_type;
typedef typename typevector_append_helper_impl<temp_type, APPEND_T, (INDEX_V + 1), SIZE_V>::type type;
};

template <typename VEC_T, typename APPEND_T, zll::uint_fast32_t INDEX_V>
struct typevector_append_helper_impl<VEC_T, APPEND_T, INDEX_V, INDEX_V> {
typedef VEC_T type;
};

template <typename VEC_T, typename APPEND_T, bool = is_typevector<APPEND_T>::value>
struct typevector_append_helper {
typedef typename push_back<VEC_T, APPEND_T>::type type;
};

template <typename VEC_T, typename APPEND_T>
struct typevector_append_helper<VEC_T, APPEND_T, true> {
static const zll::uint_fast32_t new_size = zll::meta::size<VEC_T>::value + zll::meta::size<APPEND_T>::value;
ZLL_STATIC_ASSERT((new_size <= 20)); // only 20 elements are support
typedef typename typevector_append_helper_impl<VEC_T, APPEND_T, 0, size<APPEND_T>::value>::type type;
};

} // namespace detail

template <typename HEAD_T, typename TAIL_T, typename T>
struct append<typevector<HEAD_T, TAIL_T>, T> {
typedef typename detail::typevector_append_helper<typevector<HEAD_T, TAIL_T>, T>::type type;
};

template <typename T01, typename T02, typename T03, typename T04, typename T05, typename T06, typename T07,
typename T08, typename T09, typename T10, typename T11, typename T12, typename T13, typename T14,
typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename APPEND_T>
struct append<
typevector<T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20>,
APPEND_T> {
typedef typevector<T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19,
T20>
vector_type;

typedef typename detail::typevector_append_helper<vector_type, APPEND_T>::type type;
};

} // namespace meta
} // namespace zll

#endif // ZLL_META_TYPES_TYPEVECTOR_APPEND_HPP
157 changes: 157 additions & 0 deletions include/zll/meta/types/typevector/at.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#ifndef ZLL_META_TYPES_TYPEVECTOR_AT_HPP
#define ZLL_META_TYPES_TYPEVECTOR_AT_HPP

#include "zll/debug/static_assert.hpp"

#include "zll/meta/types/at.hpp"
#include "zll/meta/types/typevector/size.hpp"
#include "zll/meta/types/typevector/typevector.hpp"
#include "zll/meta/types/typevector/is_typevector.hpp"

#include "zll/cstdint.hpp"

namespace zll {
namespace meta {

namespace detail {

template <typename T, zll::uint_fast32_t INDEX_V>
struct typevector_at_helper_impl;

template <typename T>
struct typevector_at_helper_impl<T, 0U> {
typedef typename T::item00 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 1U> {
typedef typename T::item01 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 2U> {
typedef typename T::item02 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 3U> {
typedef typename T::item03 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 4U> {
typedef typename T::item04 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 5U> {
typedef typename T::item05 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 6U> {
typedef typename T::item06 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 7U> {
typedef typename T::item07 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 8U> {
typedef typename T::item08 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 9U> {
typedef typename T::item09 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 10U> {
typedef typename T::item10 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 11U> {
typedef typename T::item11 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 12U> {
typedef typename T::item12 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 13U> {
typedef typename T::item13 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 14U> {
typedef typename T::item14 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 15U> {
typedef typename T::item15 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 16U> {
typedef typename T::item16 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 17U> {
typedef typename T::item17 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 18U> {
typedef typename T::item18 type;
};

template <typename T>
struct typevector_at_helper_impl<T, 19U> {
typedef typename T::item19 type;
};

template <typename T, zll::uint_fast32_t INDEX_V, bool = is_typevector<T>::value>
struct typevector_at_helper;

template <typename T, zll::uint_fast32_t INDEX_V>
struct typevector_at_helper<T, INDEX_V, true> {
typedef typename typevector_at_helper_impl<T, INDEX_V>::type type;
};

} // namespace detail

template <typename T01, typename T02, typename T03, typename T04, typename T05, typename T06, typename T07,
typename T08, typename T09, typename T10, typename T11, typename T12, typename T13, typename T14,
typename T15, typename T16, typename T17, typename T18, typename T19, typename T20,
zll::uint_fast32_t INDEX_V>
struct at<
typevector<T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20>,
INDEX_V> {
typedef typevector<T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19,
T20>
vector_type;

// check if index is out of range
ZLL_STATIC_ASSERT((INDEX_V < zll::meta::size<vector_type>::value));

typedef typename detail::typevector_at_helper<vector_type, INDEX_V>::type type;
};

} // namespace meta
} // namespace zll

#endif // ZLL_META_TYPES_TYPEVECTOR_AT_HPP
56 changes: 56 additions & 0 deletions include/zll/meta/types/typevector/contains.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

#ifndef ZLL_META_TYPES_TYPEVECTOR_CONTAINS_HPP
#define ZLL_META_TYPES_TYPEVECTOR_CONTAINS_HPP

#include "zll/meta/integral_constant.hpp"

#include "zll/meta/types/contains.hpp"
#include "zll/meta/types/typevector/typevector.hpp"
#include "zll/meta/types/typevector/at.hpp"
#include "zll/meta/types/typevector/size.hpp"

#include "zll/meta/traits/is_same.hpp"

namespace zll {
namespace meta {

namespace detail {

template <typename VEC_T, typename T, zll::uint_fast32_t INDEX_V, zll::uint_fast32_t SIZE_V>
struct typevector_contains_helper_impl {
static const bool same = zll::meta::is_same<typename at<VEC_T, INDEX_V>::type, T>::value;
static const bool value = same ? true : typevector_contains_helper_impl<VEC_T, T, (INDEX_V + 1), SIZE_V>::value;
};

template <typename VEC_T, typename T, zll::uint_fast32_t INDEX_V>
struct typevector_contains_helper_impl<VEC_T, T, INDEX_V, INDEX_V> {
static const bool value = false;
};

template <typename VEC_T, typename T>
struct typevector_contains_helper {
static const bool value = typevector_contains_helper_impl<VEC_T, T, 0, size<VEC_T>::value>::value;
};

} // namespace detail

template <typename T01, typename T02, typename T03, typename T04, typename T05, typename T06, typename T07,
typename T08, typename T09, typename T10, typename T11, typename T12, typename T13, typename T14,
typename T15, typename T16, typename T17, typename T18, typename T19, typename T20, typename SEARCH_T>
struct contains<
typevector<T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20>,
SEARCH_T>
: zll::meta::bool_constant<
detail::typevector_contains_helper<typevector<T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12, T13,
T14, T15, T16, T17, T18, T19, T20>,
SEARCH_T>::value> {};

} // namespace meta
} // namespace zll

#endif // ZLL_META_TYPES_TYPEVECTOR_CONTAINS_HPP
Loading

0 comments on commit 99d062f

Please sign in to comment.