2015-04-20 18:06:47 +00:00
|
|
|
/* 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;
|
|
|
|
|
2015-05-20 21:05:41 +00:00
|
|
|
initializer_list(const T *v, size_t n): p_buf(v), p_len(n) {}
|
2015-04-20 18:06:47 +00:00
|
|
|
public:
|
2015-05-25 18:07:27 +00:00
|
|
|
typedef size_t SizeType;
|
|
|
|
typedef ptrdiff_t DiffType;
|
|
|
|
typedef T ValType;
|
|
|
|
typedef const T &RefType;
|
|
|
|
typedef const T &ConstRefType;
|
|
|
|
typedef const T *PtrType;
|
|
|
|
typedef const T *ConstPtrType;
|
2015-05-25 19:46:49 +00:00
|
|
|
typedef octa::PointerRange<const T> RangeType;
|
|
|
|
typedef octa::PointerRange<const T> ConstRangeType;
|
2015-04-20 18:06:47 +00:00
|
|
|
|
2015-05-20 21:05:41 +00:00
|
|
|
initializer_list(): p_buf(nullptr), p_len(0) {}
|
2015-04-20 18:06:47 +00:00
|
|
|
|
2015-05-20 21:05:41 +00:00
|
|
|
size_t length() const { return p_len; }
|
2015-04-20 18:06:47 +00:00
|
|
|
|
2015-05-25 18:07:27 +00:00
|
|
|
const T *data() const { return p_buf; }
|
2015-04-20 18:06:47 +00:00
|
|
|
|
2015-05-24 01:31:54 +00:00
|
|
|
octa::PointerRange<const T> each() {
|
2015-04-20 18:06:47 +00:00
|
|
|
return octa::PointerRange<const T>(p_buf, p_len);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace octa {
|
|
|
|
template<typename T> using InitializerList = std::initializer_list<T>;
|
2015-05-26 18:25:20 +00:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
auto each(InitializerList<T> init) -> decltype(init.each()) {
|
|
|
|
return init.each();
|
|
|
|
}
|
2015-04-20 18:06:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|