This commit is contained in:
Erik Frojdh
2019-08-07 15:36:27 +02:00
parent 4ceee97c03
commit 65ebd0baf0
3 changed files with 45 additions and 34 deletions

View File

@ -13,6 +13,7 @@
#include <iostream>
#include <vector>
#include "TimeHelper.h"
#include "ToString.h"
#include "container_utils.h"
@ -30,6 +31,34 @@ template <class T, class Allocator = std::allocator<T>> class Result {
Result() = default;
Result(std::initializer_list<T> list) : vec(list){};
template <typename V, typename = typename std::enable_if<
std::is_integral<V>::value &&
std::is_same<T, time::ns>::value>::type>
Result(const std::vector<V> &from) {
vec.reserve(from.size());
for (const auto &item : from)
vec.push_back(T(item));
}
template <typename V, typename = typename std::enable_if<
std::is_integral<V>::value &&
std::is_same<T, time::ns>::value>::type>
Result(std::vector<V> &from) {
vec.reserve(from.size());
for (const auto &item : from)
vec.push_back(T(item));
}
template <typename V, typename = typename std::enable_if<
std::is_integral<V>::value &&
std::is_same<T, time::ns>::value>::type>
Result(std::vector<V> &&from) {
vec.reserve(from.size());
for (const auto &item : from)
vec.push_back(T(item));
}
/**
* Forward arguments to the constructor of std::vector
* @tparam Args template paramter pack to forward
@ -82,9 +111,6 @@ template <class T, class Allocator = std::allocator<T>> class Result {
/** Convert Result<T> to std::vector<T> */
operator std::vector<T>() { return vec; }
/** Convert Result<T> to T using squash() */
operator T() { return squash(); }
};
/**