| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + #ifndef BOOST_BUILD_PCH_ENABLED | ||
| 2 | + #define BOOST_BUILD_PCH_ENABLED | ||
| 3 | + #include <boost/test/included/unit_test.hpp> | ||
| 4 | + #endif | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,4 @@ | |||
| 1 | + double getPiNthDigit(int digits) | ||
| 2 | + { | ||
| 3 | + return 3; | ||
| 4 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + #ifndef GET_PI_NTH_DIGIT | ||
| 2 | + #define GET_PI_NTH_DIGIT | ||
| 3 | + | ||
| 4 | + double getPiNthDigit(int digits); | ||
| 5 | + | ||
| 6 | + #endif | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,10 @@ | |||
| 1 | + #define BOOST_TEST_DYN_LINK | ||
| 2 | + #define BOOST_TEST_MODULE examples | ||
| 3 | + #include <boost/test/unit_test.hpp> | ||
| 4 | + #include "find_nth_pi_digit.h" | ||
| 5 | + | ||
| 6 | + BOOST_AUTO_TEST_CASE(pi_digits) | ||
| 7 | + { | ||
| 8 | + BOOST_CHECK_EQUAL(getPiNthDigit(0), 3); | ||
| 9 | + BOOST_CHECK_CLOSE(5.0001, 5 + 0.001, 0.02); | ||
| 10 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + #include <iostream> | ||
| 2 | + | ||
| 3 | + class Foo | ||
| 4 | + { | ||
| 5 | + public: | ||
| 6 | + explicit Foo (void) {}; | ||
| 7 | + Foo(Foo&& rhs) | ||
| 8 | + { | ||
| 9 | + std::cout << "Inside of a move ctr" << '\n'; | ||
| 10 | + } | ||
| 11 | + private: | ||
| 12 | + }; | ||
| 13 | + | ||
| 14 | + int main() | ||
| 15 | + { | ||
| 16 | + Foo f; | ||
| 17 | + | ||
| 18 | + return 0; | ||
| 19 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,49 @@ | |||
| 1 | + #include <iostream> | ||
| 2 | + #include <unordered_map> | ||
| 3 | + #include <memory> | ||
| 4 | + #include <string> | ||
| 5 | + | ||
| 6 | + class Base | ||
| 7 | + { | ||
| 8 | + public: | ||
| 9 | + explicit Base (void) = default; | ||
| 10 | + virtual ~Base () = default; | ||
| 11 | + | ||
| 12 | + Base (const Base&) = delete; | ||
| 13 | + Base (const Base&&) = delete; | ||
| 14 | + Base operator=(const Base&) = delete; | ||
| 15 | + Base operator=(const Base&&) = delete; | ||
| 16 | + }; | ||
| 17 | + | ||
| 18 | + template <typename T> | ||
| 19 | + T* getHashedT(const std::string& key, std::unordered_map<std::string, std::unique_ptr<T>>& map) | ||
| 20 | + { | ||
| 21 | + std::unique_ptr<T>& entry = map[key]; | ||
| 22 | + if (entry) | ||
| 23 | + { | ||
| 24 | + return entry.get(); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + entry = std::make_unique<T>(); | ||
| 28 | + return entry.get(); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + template <typename T> | ||
| 32 | + T* getHashetTInsertVersion(const std::string& key, std::unordered_map<std::string, std::unique_ptr<T>>& m) | ||
| 33 | + { | ||
| 34 | + // This creates a pair (passed a string and creates unique_ptr and Base object at every lookup) | ||
| 35 | + auto r = m.insert(std::make_pair<std::string, std::unique_ptr<T>>(key, nullptr)); | ||
| 36 | + if (r.first) | ||
| 37 | + { | ||
| 38 | + r.second = std::make_unique<T>(); | ||
| 39 | + } | ||
| 40 | + return r.second.get(); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + int main() | ||
| 44 | + { | ||
| 45 | + std::unordered_map<std::string, std::unique_ptr<Base>> m; | ||
| 46 | + auto b = getHashedT("first", m); | ||
| 47 | + | ||
| 48 | + return 0; | ||
| 49 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments