Created
April 25, 2013 22:07
-
-
Save CTMacUser/5463628 to your computer and use it in GitHub Desktop.
Use when a built-in array types needs extents to be stripped, but the amount to strip is between one and all (exclusive). I thought I needed this for another project, but I ended up not needing it (yet). So it's here so I won't forget, and for posterity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2013 Daryle Walker. | |
// Distributed under the Boost Software License, Version 1.0. (See a copy at | |
// <http://www.boost.org/LICENSE_1_0.txt>.) | |
#ifndef REMOVE_SOME_EXTENTS_HPP | |
#define REMOVE_SOME_EXTENTS_HPP | |
#include <cstddef> | |
// Forward declarations ----------------------------------------------------// | |
/** \brief Type-traits for removing some extents of a multi-level built-in | |
array type. | |
\details This type-traits class (template) gives an option between removing | |
one extent (`std::remove_extent`) or all of them | |
(`std::remove_all_extents`). | |
\tparam Array The type to strip. | |
\tparam Count The number of extents to strip. | |
*/ | |
template < typename Array, std::size_t Count > | |
struct remove_some_extents; | |
// Array-extent stripping traits class template specializations ------------// | |
//! Case with indefinite array but no extents to strip | |
template < typename T > | |
struct remove_some_extents< T[], 0u > | |
{ typedef T type[]; }; | |
//! Case with definite array but no extents to strip | |
template < typename T, std::size_t N > | |
struct remove_some_extents< T[N], 0u > | |
{ typedef T type[N]; }; | |
//! Case with indefinite array and extents to strip | |
template < typename T, std::size_t L > | |
struct remove_some_extents< T[], L > | |
{ typedef typename remove_some_extents<T, L - 1u>::type type; }; | |
//! Case with definite array and extents to strip | |
template < typename T, std::size_t N, std::size_t L > | |
struct remove_some_extents< T[N], L > | |
{ typedef typename remove_some_extents<T, L - 1u>::type type; }; | |
//! General case | |
template < typename A, std::size_t > | |
struct remove_some_extents | |
{ typedef A type; }; | |
#endif // REMOVE_SOME_EXTENTS_HPP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment