rhubarb-lip-sync/src/pairs.h

21 lines
664 B
C
Raw Normal View History

2016-05-12 19:21:25 +00:00
#pragma once
#include <vector>
template<typename TCollection>
std::vector<std::pair<typename TCollection::value_type, typename TCollection::value_type>> getPairs(const TCollection& collection) {
using TElement = typename TCollection::value_type;
using TPair = std::pair<TElement, TElement>;
auto begin = collection.begin();
auto end = collection.end();
if (begin == end || ++TCollection::const_iterator(begin) == end) {
return std::vector<TPair>();
}
std::vector<TPair> result;
for (auto first = begin, second = ++TCollection::const_iterator(begin); second != end; ++first, ++second) {
result.push_back(TPair(*first, *second));
}
return result;
}