Skip to content

Instantly share code, notes, and snippets.

@Voltra
Created August 22, 2019 18:27
Show Gist options
  • Save Voltra/ac3aae80e647172d95106b735c01be73 to your computer and use it in GitHub Desktop.
Save Voltra/ac3aae80e647172d95106b735c01be73 to your computer and use it in GitHub Desktop.
C++ UFCS operator@
template <class Range>
Range firstHalf(const Range& r){
auto&& begin = std::begin(r);
auto&& begin_ = begin;
return make<Range>(
begin,
std::next(
begin_,
std::distance(begin, std::end(r))
)
);
}
int main(){
std::vector<int> v = {0,1,2,3,4,5,6};
assert(firstHalf(v) == v@firstHalf());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment