Slight performance improvement.
This commit is contained in:
@@ -1,26 +1,31 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <vector>
|
#include <iterator>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace fmri
|
namespace fmri
|
||||||
{
|
{
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
inline T identity(T t) {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
inline std::vector <T> read_vector(const std::string& filename)
|
inline std::vector <T> read_vector(const std::string& filename)
|
||||||
{
|
{
|
||||||
std::ifstream input(filename);
|
std::ifstream input(filename);
|
||||||
assert(input.good());
|
assert(input.good());
|
||||||
|
|
||||||
T t;
|
|
||||||
std::vector<T> res;
|
std::vector<T> res;
|
||||||
|
std::transform(std::istream_iterator<T>(input),
|
||||||
while (input >> t) {
|
std::istream_iterator<T>(),
|
||||||
res.push_back(t);
|
identity<T>, std::back_inserter(res));
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -44,12 +49,10 @@ namespace fmri
|
|||||||
template<class T, class U>
|
template<class T, class U>
|
||||||
std::vector<std::pair<T, U>> combine(const std::vector<T>& a, const std::vector<U>& b)
|
std::vector<std::pair<T, U>> combine(const std::vector<T>& a, const std::vector<U>& b)
|
||||||
{
|
{
|
||||||
assert(a.size() == b.size());
|
|
||||||
std::vector<std::pair<T, U>> res;
|
std::vector<std::pair<T, U>> res;
|
||||||
|
std::transform(a.begin(), a.end(), b.begin(),
|
||||||
for (size_t i = 0; i < a.size(); ++i) {
|
std::back_inserter(res),
|
||||||
res.emplace_back(a[i], b[i]);
|
[] (const T& a, const U& b) -> auto { return std::make_pair(a, b); });
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user