Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <iostream>
- //#include <map>
- //#include <string>
- //#include <vector>
- //#include <future>
- //#include <optional>
- //#include <algorithm>
- //#include <thread>
- //
- //using namespace std;
- //
- //template <typename T>
- //class LazyValue
- //{
- //public:
- // explicit LazyValue(std::function<T()> init) : init_(std::move(init)) {}
- //
- // const T& Get() const
- // {
- // if (lock_guard g(m); !value)
- // {
- // value = init_();
- // }
- // return *value;
- // }
- //private:
- // std::function<T()> init_;
- // mutable std::optional<T> value;
- // mutable mutex m;
- //};
- //
- //int main()
- //{
- // LazyValue<map<string, int>> city_population([&]
- // {
- // return map<string, int> {
- // {"Москва", 11514330},
- // { "Санкт-Петербург", 1498921 }
- // };
- // });
- //
- // auto kernel = [&]
- // {
- // return city_population.Get().at("Тула");
- // };
- //
- // vector<std::future<int>> ts;
- //
- // for (size_t i = 0; i < 25; ++i)
- // {
- // ts.push_back(async(kernel));
- // }
- // for (auto& t : ts)
- // {
- // t.get();
- // }
- // const string saratov = "Саратов";
- //
- // cout << saratov << ' ' << city_population.Get().at(saratov);
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement