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.
|
|
|
|
*/
|
|
|
|
|
2015-07-13 19:08:55 +00:00
|
|
|
#ifndef OSTD_INITIALIZER_LIST_HH
|
|
|
|
#define OSTD_INITIALIZER_LIST_HH
|
2015-04-20 18:06:47 +00:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2015-07-13 19:08:55 +00:00
|
|
|
#include "ostd/range.hh"
|
2015-04-20 18:06:47 +00:00
|
|
|
|
2015-07-13 19:08:55 +00:00
|
|
|
#ifndef OSTD_ALLOW_CXXSTD
|
2015-04-20 18:06:47 +00:00
|
|
|
/* must be in std namespace otherwise the compiler won't know about it */
|
|
|
|
namespace std {
|
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-06-03 21:56:01 +00:00
|
|
|
class initializer_list {
|
2015-06-04 21:57:06 +00:00
|
|
|
const T *p_buf;
|
2015-07-13 19:07:14 +00:00
|
|
|
ostd::Size p_len;
|
2015-04-20 18:06:47 +00:00
|
|
|
|
2015-07-13 19:07:14 +00:00
|
|
|
constexpr initializer_list(const T *v, ostd::Size n): p_buf(v), p_len(n) {}
|
2015-06-03 21:56:01 +00:00
|
|
|
public:
|
2015-06-28 19:39:27 +00:00
|
|
|
constexpr initializer_list(): p_buf(nullptr), p_len(0) {}
|
2015-06-03 21:56:01 +00:00
|
|
|
|
2015-07-13 19:07:14 +00:00
|
|
|
constexpr ostd::Size size() const { return p_len; }
|
2015-06-03 21:56:01 +00:00
|
|
|
|
2015-06-28 19:39:27 +00:00
|
|
|
constexpr const T *begin() const { return p_buf; }
|
|
|
|
constexpr const T *end() const { return p_buf + p_len; }
|
2015-06-03 21:56:01 +00:00
|
|
|
};
|
2015-04-20 18:06:47 +00:00
|
|
|
|
|
|
|
}
|
2015-05-27 22:49:59 +00:00
|
|
|
#else
|
|
|
|
#include <initializer_list>
|
|
|
|
#endif
|
2015-04-20 18:06:47 +00:00
|
|
|
|
2015-07-13 19:07:14 +00:00
|
|
|
namespace ostd {
|
2015-05-28 18:58:05 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T> using InitializerList = std::initializer_list<T>;
|
2015-06-03 21:56:01 +00:00
|
|
|
|
2015-06-04 21:57:06 +00:00
|
|
|
template<typename T>
|
2015-07-05 22:59:36 +00:00
|
|
|
PointerRange<const T> iter(std::initializer_list<T> init) {
|
|
|
|
return PointerRange<const T>(init.begin(), init.end());
|
2015-06-03 21:56:01 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 20:18:43 +00:00
|
|
|
template<typename T>
|
2015-07-05 22:59:36 +00:00
|
|
|
PointerRange<const T> citer(std::initializer_list<T> init) {
|
|
|
|
return PointerRange<const T>(init.begin(), init.end());
|
2015-06-09 20:18:43 +00:00
|
|
|
}
|
|
|
|
|
2015-04-20 18:06:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|