Created
July 13, 2017 19:26
-
-
Save AlexBolotsin/462a0409aafb8f66ec5db8abd6031541 to your computer and use it in GitHub Desktop.
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 <iostream> | |
#include <algorithm> | |
#include <vector> | |
template <typename T> | |
using Storage = std::vector<T>; | |
class ValuesWrapper; | |
class BigBlobData | |
{ | |
friend ValuesWrapper; | |
Storage<int> _someValues; | |
Storage<float> _somePoints; | |
Storage<std::string> _someStrings; | |
public: | |
void SetPoints(Storage<float> someValues) { | |
std::merge(someValues.begin(), someValues.end(), | |
_someValues.begin(), _someValues.end(), | |
std::back_inserter(_someValues)); | |
} | |
}; | |
class ValuesWrapper { | |
const Storage<int>& _someValues; | |
public: | |
ValuesWrapper(const BigBlobData& blob) : _someValues(blob._someValues) | |
{ | |
} | |
class Iterator | |
{ | |
const int* _data; | |
public: | |
Iterator(const int* data) : _data(data) {} | |
Iterator operator++() | |
{ | |
_data++; | |
return {_data}; | |
} | |
bool operator==(const Iterator& rhs) | |
{ | |
return _data == rhs._data; | |
} | |
bool operator!=(const Iterator& rhs) | |
{ | |
return !(_data == rhs._data); | |
} | |
int operator*() | |
{ | |
return *_data; | |
} | |
}; | |
Iterator begin() { return Iterator(_someValues.data()); } | |
Iterator end() { return Iterator(_someValues.data() + _someValues.size()); } | |
}; | |
int main(int argc, char** argv) | |
{ | |
BigBlobData blob; | |
blob.SetPoints({1, 3, 4, 6, 7 , 8, 11, 13, 15, 16, 19, 20}); | |
blob.SetPoints({32, 34, 42, 53, 67, 71}); | |
for (int value : ValuesWrapper(blob)) | |
std::cout << value << " "; | |
std::cout << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment