Skip to content

Commit

Permalink
Add make_char_arr() function
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyelewis committed Mar 14, 2018
1 parent 74277b3 commit 736d31c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions source/src_common/common/char_arr_type_aliases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@

namespace cath {

namespace detail {

/// \brief Implementation of make_char_arr() with the indices of the integers as template parameters
template <size_t Length, size_t... Indices>
constexpr auto make_char_arr_impl(const char ( &arg_cstring )[ Length ], ///< The C-string from which the std::array should be built
std::integer_sequence<size_t, Indices...> ///< integer_sequence encoding the indices of the individual characters
) {
return std::array<char, Length>{ arg_cstring[ Indices ]... };
}

} // namespace detail

/// \brief Make a std::array of the characters in the specified C-string
template <size_t Length>
constexpr auto make_char_arr(const char ( &arg_cstring )[ Length ] ///< The C-string from which the std::array should be built
) {
return detail::make_char_arr_impl( arg_cstring, std::make_index_sequence<Length>{} );
}

/// \brief A type alias for a std::array of 2 chars
using char_2_arr = std::array<char, 2>;

Expand Down

0 comments on commit 736d31c

Please sign in to comment.