Created
March 12, 2013 01:37
-
-
Save jdeng/5139562 to your computer and use it in GitHub Desktop.
Constructor inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <iostream> | |
template <typename Iterator> | |
struct range: public std::pair<Iterator, Iterator> | |
{ | |
using Parent = std::pair<Iterator, Iterator>; | |
template <typename... Arg> range(Arg&& ... arg): Parent(std::forward<Arg>(arg) ...) {} | |
Iterator begin() { return this->first; } | |
Iterator end() { return this->second; } | |
}; | |
template <typename Iterator> | |
range<Iterator> make_range(Iterator a, Iterator b) { return range<Iterator>(a, b); } | |
int main() | |
{ | |
std::vector<int> input{1, 2, 3, 4, 5, 6}; | |
auto range = make_range(input.cbegin(), input.cbegin() + 3); | |
for (auto& x: range) std::cout << x << ","; std::cout << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment