2017-01-25 01:44:22 +01:00
|
|
|
/* OctaSTD extensions for std::vector.
|
2015-04-06 01:05:21 +02:00
|
|
|
*
|
2015-04-12 22:41:02 +02:00
|
|
|
* This file is part of OctaSTD. See COPYING.md for futher information.
|
2015-04-06 01:05:21 +02:00
|
|
|
*/
|
|
|
|
|
2015-07-13 21:08:55 +02:00
|
|
|
#ifndef OSTD_VECTOR_HH
|
|
|
|
#define OSTD_VECTOR_HH
|
2015-04-06 01:05:21 +02:00
|
|
|
|
2017-01-25 01:44:22 +01:00
|
|
|
#include <vector>
|
2015-04-14 23:16:06 +02:00
|
|
|
|
2015-07-13 21:08:55 +02:00
|
|
|
#include "ostd/range.hh"
|
2015-04-06 01:05:21 +02:00
|
|
|
|
2015-07-13 21:07:14 +02:00
|
|
|
namespace ostd {
|
2015-06-04 01:06:43 +02:00
|
|
|
|
2017-01-25 01:44:22 +01:00
|
|
|
template<typename T>
|
2017-01-26 00:27:54 +01:00
|
|
|
struct ranged_traits<std::vector<T>> {
|
|
|
|
static PointerRange<T> iter(std::vector<T> &v) {
|
|
|
|
return PointerRange<T>{v.data(), v.size()};
|
|
|
|
}
|
|
|
|
};
|
2015-07-13 01:24:14 +02:00
|
|
|
|
2017-01-25 01:44:22 +01:00
|
|
|
template<typename T>
|
2017-01-26 00:27:54 +01:00
|
|
|
struct ranged_traits<std::vector<T> const> {
|
|
|
|
static PointerRange<T const> iter(std::vector<T> const &v) {
|
|
|
|
return PointerRange<T const>{v.data(), v.size()};
|
|
|
|
}
|
|
|
|
};
|
2015-07-13 01:24:14 +02:00
|
|
|
|
2017-01-25 01:44:22 +01:00
|
|
|
template<typename T, typename R>
|
|
|
|
inline std::vector<T> make_vector(R range) {
|
|
|
|
/* TODO: specialize for contiguous ranges and matching value types */
|
|
|
|
std::vector<T> ret;
|
|
|
|
for (; !range.empty(); range.pop_front()) {
|
|
|
|
ret.push_back(range.front());
|
|
|
|
}
|
|
|
|
return ret;
|
2015-07-13 01:24:14 +02:00
|
|
|
}
|
|
|
|
|
2017-01-25 01:44:22 +01:00
|
|
|
template<typename R>
|
|
|
|
inline std::vector<RangeValue<R>> make_vector(R range) {
|
|
|
|
return make_vector<RangeValue<R>>(std::move(range));
|
2015-07-13 01:24:14 +02:00
|
|
|
}
|
|
|
|
|
2015-07-13 21:07:14 +02:00
|
|
|
} /* namespace ostd */
|
2015-04-06 01:05:21 +02:00
|
|
|
|
2016-02-07 22:17:15 +01:00
|
|
|
#endif
|