2015-04-20 20:06:47 +02:00
|
|
|
/* Initializer list support for OctaSTD.
|
|
|
|
*
|
|
|
|
* This file is part of OctaSTD. See COPYING.md for futher information.
|
|
|
|
*/
|
|
|
|
|
2015-07-13 21:08:55 +02:00
|
|
|
#ifndef OSTD_INITIALIZER_LIST_HH
|
|
|
|
#define OSTD_INITIALIZER_LIST_HH
|
2015-04-20 20:06:47 +02:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2015-07-13 21:08:55 +02:00
|
|
|
#include "ostd/range.hh"
|
2015-04-20 20:06:47 +02:00
|
|
|
|
2015-07-13 21:08:55 +02:00
|
|
|
#ifndef OSTD_ALLOW_CXXSTD
|
2015-04-20 20:06:47 +02:00
|
|
|
/* must be in std namespace otherwise the compiler won't know about it */
|
|
|
|
namespace std {
|
|
|
|
|
2015-06-04 23:57:06 +02:00
|
|
|
template<typename T>
|
2015-06-03 23:56:01 +02:00
|
|
|
class initializer_list {
|
2016-06-23 20:18:35 +02:00
|
|
|
T const *p_buf;
|
2015-07-13 21:07:14 +02:00
|
|
|
ostd::Size p_len;
|
2015-04-20 20:06:47 +02:00
|
|
|
|
2016-06-23 20:18:35 +02:00
|
|
|
constexpr initializer_list(T const *v, ostd::Size n): p_buf(v), p_len(n) {}
|
2015-06-03 23:56:01 +02:00
|
|
|
public:
|
2015-06-28 21:39:27 +02:00
|
|
|
constexpr initializer_list(): p_buf(nullptr), p_len(0) {}
|
2015-06-03 23:56:01 +02:00
|
|
|
|
2015-07-13 21:07:14 +02:00
|
|
|
constexpr ostd::Size size() const { return p_len; }
|
2015-06-03 23:56:01 +02:00
|
|
|
|
2016-06-23 20:18:35 +02:00
|
|
|
constexpr T const *begin() const { return p_buf; }
|
|
|
|
constexpr T const *end() const { return p_buf + p_len; }
|
2015-06-03 23:56:01 +02:00
|
|
|
};
|
2015-04-20 20:06:47 +02:00
|
|
|
|
|
|
|
}
|
2015-05-28 00:49:59 +02:00
|
|
|
#else
|
|
|
|
#include <initializer_list>
|
|
|
|
#endif
|
2015-04-20 20:06:47 +02:00
|
|
|
|
2015-07-13 21:07:14 +02:00
|
|
|
namespace ostd {
|
2015-05-28 20:58:05 +02:00
|
|
|
|
2016-07-31 21:40:25 +02:00
|
|
|
template<typename T>
|
|
|
|
using InitializerList = std::initializer_list<T>;
|
2015-06-03 23:56:01 +02:00
|
|
|
|
2015-06-04 23:57:06 +02:00
|
|
|
template<typename T>
|
2016-06-23 20:18:35 +02:00
|
|
|
PointerRange<T const> iter(std::initializer_list<T> init) {
|
|
|
|
return PointerRange<T const>(init.begin(), init.end());
|
2015-06-03 23:56:01 +02:00
|
|
|
}
|
|
|
|
|
2015-06-09 22:18:43 +02:00
|
|
|
template<typename T>
|
2016-06-23 20:18:35 +02:00
|
|
|
PointerRange<T const> citer(std::initializer_list<T> init) {
|
|
|
|
return PointerRange<T const>(init.begin(), init.end());
|
2015-06-09 22:18:43 +02:00
|
|
|
}
|
|
|
|
|
2015-04-20 20:06:47 +02:00
|
|
|
}
|
|
|
|
|
2016-02-07 22:17:15 +01:00
|
|
|
#endif
|