replace ArrayRange by tcb::span (reproduction of std::span)

This commit is contained in:
Garux
2021-10-24 08:32:10 +03:00
parent 4726542134
commit d812cbd4d4
30 changed files with 544 additions and 158 deletions

View File

@@ -20,48 +20,10 @@
*/
#pragma once
#include "span.h"
/// \file
/// \brief Macros for automatically converting a compile-time-sized array to a range.
using tcb::Span;
template<typename Element>
struct ArrayRange
{
typedef Element* Iterator;
ArrayRange( Iterator first, Iterator last )
: first( first ), last( last ){
}
Iterator first;
Iterator last;
};
using StringArrayRange = Span<const char *const>;
template<typename Element>
inline ArrayRange<Element> makeArrayRange( Element* first, Element* last ){
return ArrayRange<Element>( first, last );
}
template<typename Element>
struct ArrayConstRange
{
typedef const Element* Iterator;
ArrayConstRange( Iterator first, Iterator last )
: first( first ), last( last ){
}
Iterator first;
Iterator last;
};
template<typename Element>
inline ArrayConstRange<Element> makeArrayRange( const Element* first, const Element* last ){
return ArrayConstRange<Element>( first, last );
}
#define ARRAY_SIZE( array ) ( sizeof( array ) / sizeof( *array ) )
#define ARRAY_END( array ) ( array + ARRAY_SIZE( array ) )
#define ARRAY_RANGE( array ) ( makeArrayRange( array, ARRAY_END( array ) ) )
typedef ArrayConstRange<const char*> StringArrayRange;
#define STRING_ARRAY_RANGE( array ) ( StringArrayRange( array, ARRAY_END( array ) ) )
typedef ArrayRange<const char> StringRange;
using StringRange = Span<const char>;