forked from OctaForge/libostd
move initializer lists into initializer_list.h + add new .range() method to retrieve a PointerRange to it
This commit is contained in:
parent
9885909485
commit
d68d381f72
|
@ -6,11 +6,12 @@
|
|||
#ifndef OCTA_ALGORITHM_H
|
||||
#define OCTA_ALGORITHM_H
|
||||
|
||||
#include "math.h"
|
||||
#include <math.h>
|
||||
|
||||
#include "octa/functional.h"
|
||||
#include "octa/range.h"
|
||||
#include "octa/utility.h"
|
||||
#include "octa/initializer_list.h"
|
||||
|
||||
namespace octa {
|
||||
template<typename R, typename U>
|
||||
|
@ -182,25 +183,21 @@ namespace octa {
|
|||
|
||||
template<typename T>
|
||||
inline T min(InitializerList<T> il) {
|
||||
return min_element(PointerRange<const T>(il.get(),
|
||||
il.get() + il.length())).first();
|
||||
return min_element(il.range()).first();
|
||||
}
|
||||
template<typename T, typename C>
|
||||
inline T min(InitializerList<T> il, C compare) {
|
||||
return min_element(PointerRange<const T>(il.get(),
|
||||
il.get() + il.length(), compare)).first();
|
||||
return min_element(il.range(), compare).first();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T max(InitializerList<T> il) {
|
||||
return max_element(PointerRange<const T>(il.get(),
|
||||
il.get() + il.length())).first();
|
||||
return max_element(il.range()).first();
|
||||
}
|
||||
|
||||
template<typename T, typename C>
|
||||
inline T max(InitializerList<T> il, C compare) {
|
||||
return max_element(PointerRange<const T>(il.get(),
|
||||
il.get() + il.length(), compare)).first();
|
||||
return max_element(il.range(), compare).first();
|
||||
}
|
||||
|
||||
template<typename R, typename F>
|
||||
|
|
48
octa/initializer_list.h
Normal file
48
octa/initializer_list.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/* Initializer list support for OctaSTD.
|
||||
*
|
||||
* This file is part of OctaSTD. See COPYING.md for futher information.
|
||||
*/
|
||||
|
||||
#ifndef OCTA_INITIALIZER_LIST_H
|
||||
#define OCTA_INITIALIZER_LIST_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "octa/range.h"
|
||||
|
||||
/* must be in std namespace otherwise the compiler won't know about it */
|
||||
namespace std {
|
||||
template<typename T>
|
||||
class initializer_list {
|
||||
const T *p_buf;
|
||||
size_t p_len;
|
||||
|
||||
initializer_list(const T *v, size_t n): p_buf(v), p_len(n) {}
|
||||
public:
|
||||
struct type {
|
||||
typedef T value;
|
||||
typedef T &reference;
|
||||
typedef const T &const_reference;
|
||||
typedef T *pointer;
|
||||
typedef const T *const_pointer;
|
||||
typedef size_t size;
|
||||
typedef ptrdiff_t difference;
|
||||
};
|
||||
|
||||
initializer_list(): p_buf(nullptr), p_len(0) {}
|
||||
|
||||
size_t length() const { return p_len; }
|
||||
|
||||
const T *get() const { return p_buf; }
|
||||
|
||||
octa::PointerRange<const T> range() {
|
||||
return octa::PointerRange<const T>(p_buf, p_len);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace octa {
|
||||
template<typename T> using InitializerList = std::initializer_list<T>;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -8,36 +8,7 @@
|
|||
|
||||
#include <stddef.h>
|
||||
|
||||
/* must be in std namespace otherwise the compiler won't know about it */
|
||||
namespace std {
|
||||
template<typename T>
|
||||
class initializer_list {
|
||||
const T *p_buf;
|
||||
size_t p_len;
|
||||
|
||||
initializer_list(const T *v, size_t n): p_buf(v), p_len(n) {}
|
||||
public:
|
||||
struct type {
|
||||
typedef T value;
|
||||
typedef T &reference;
|
||||
typedef const T &const_reference;
|
||||
typedef T *pointer;
|
||||
typedef const T *const_pointer;
|
||||
typedef size_t size;
|
||||
typedef ptrdiff_t difference;
|
||||
};
|
||||
|
||||
initializer_list(): p_buf(nullptr), p_len(0) {}
|
||||
|
||||
size_t length() const { return p_len; }
|
||||
|
||||
const T *get() const { return p_buf; }
|
||||
};
|
||||
}
|
||||
|
||||
namespace octa {
|
||||
template<typename T> using InitializerList = std::initializer_list<T>;
|
||||
|
||||
/* aliased in traits.h later */
|
||||
namespace internal {
|
||||
template<typename T> struct RemoveReference { typedef T type; };
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "octa/utility.h"
|
||||
#include "octa/range.h"
|
||||
#include "octa/algorithm.h"
|
||||
#include "octa/initializer_list.h"
|
||||
|
||||
namespace octa {
|
||||
template<typename T>
|
||||
|
@ -264,8 +265,7 @@ namespace octa {
|
|||
}
|
||||
|
||||
T *insert(size_t idx, InitializerList<T> il) {
|
||||
return insert_range(idx, PointerRange<const T>(il.get(),
|
||||
il.get() + il.length()));
|
||||
return insert_range(idx, il.range());
|
||||
}
|
||||
|
||||
typename type::range each() {
|
||||
|
|
Loading…
Reference in a new issue