• Docs >
  • Program Listing for File tuple.hpp
Shortcuts

Program Listing for File tuple.hpp

Return to documentation for file (include/ripple/container/tuple.hpp)

#ifndef RIPPLE_CONTAINER_TUPLE_HPP
#define RIPPLE_CONTAINER_TUPLE_HPP

#include "tuple_traits.hpp"
#include "detail/basic_tuple_.hpp"

namespace ripple {

/*==--- [tuple implementation] ---------------------------------------------==*/

template <>
class Tuple<> {
  using Storage = detail::BasicTuple<>;

 public:
  ripple_all constexpr Tuple() noexcept {}

  ripple_all constexpr auto size() const noexcept -> size_t {
    return 0;
  }
};

template <typename... Ts>
class Tuple {
  using Storage = detail::BasicTuple<Ts...>;

  static constexpr size_t elements = size_t{sizeof...(Ts)};

  /*=--- [construction] ----------------------------------------------------==*/

  template <typename T, size_t... I>
  ripple_all constexpr explicit Tuple(
    T&& other, std::index_sequence<I...> extractor) noexcept
  : storage_{detail::get_impl<I>(ripple_forward(other.data()))...} {}

  Storage storage_;

 public:
  ripple_all constexpr Tuple() noexcept
  : storage_{std::decay_t<Ts>()...} {}

  ripple_all constexpr Tuple(const Ts&... es) noexcept
  : storage_{es...} {}

  template <typename... Types, non_tuple_enable_t<Types...> = 0>
  ripple_all constexpr Tuple(Types&&... es) noexcept
  : storage_{ripple_forward(es)...} {}

  /*==--- [move constructor] -----------------------------------------------==*/

  template <typename T, tuple_enable_t<T> = 0>
  ripple_all constexpr explicit Tuple(T&& other) noexcept
  : Tuple{ripple_forward(other), std::make_index_sequence<elements>{}} {}

  /*==--- [interface] ------------------------------------------------------==*/

  ripple_all constexpr auto size() const noexcept -> size_t {
    return elements;
  }

  ripple_all auto data() noexcept -> Storage& {
    return storage_;
  }

  ripple_all auto data() const noexcept -> const Storage& {
    return storage_;
  }
};

/*==--- [get implemenation] ------------------------------------------------==*/

template <size_t I, typename... Ts>
ripple_all constexpr inline auto get(const Tuple<Ts...>& tuple) noexcept
  -> const std::decay_t<nth_element_t<I, Ts...>>& {
  return detail::get_impl<I>(tuple.data());
}

template <size_t I, typename... Ts>
ripple_all constexpr inline auto get(Tuple<Ts...>& tuple) noexcept
  -> std::remove_reference_t<nth_element_t<I, Ts...>>& {
  return detail::get_impl<I>(tuple.data());
}

template <size_t I, typename... Ts>
ripple_all constexpr inline auto get(Tuple<Ts...>&& tuple) noexcept
  -> std::remove_reference_t<nth_element_t<I, Ts...>>&& {
  using DataType = decltype(tuple.data());
  return detail::get_impl<I>(
    static_cast<std::remove_reference_t<DataType>&&>(tuple.data()));
}

template <size_t I, typename... Ts>
ripple_all constexpr inline auto
get(const Tuple<Ts...>&& tuple) noexcept
  -> const std::decay_t<nth_element_t<I, Ts...>>&& {
  using DataType = decltype(tuple.data());
  return detail::get_impl<I>(
    static_cast<const std::remove_reference_t<DataType>&&>(tuple.data()));
}

/*==--- [make tuple] -------------------------------------------------------==*/

template <typename... Ts>
ripple_all constexpr inline auto
make_tuple(Ts&&... values) noexcept -> Tuple<std::decay_t<Ts>...> {
  return Tuple<std::decay_t<Ts>...>{ripple_forward(values)...};
}

} // namespace ripple

#endif // RIPPLE_CONTAINER_TUPLE_HPP

Docs

Access comprehensive developer documentation for Ripple

View Docs

Tutorials

Get tutorials to help with understand all features

View Tutorials

Examples

Find examples to help get started

View Examples