This file contains hidden or 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
| std::vector<int> v(N); | |
| // Initialize the array with random elements between 0 and 100 | |
| for_each(v.begin(), v.end(), [](int& cur){ cur = rand()%100; }); | |
| auto print_vec = [](std::ostream& out, const std::vector<int>& vec) { | |
| std:copy(v.begin(), v.end(), std::ostream_iterator<int>(out, ", ")); | |
| out << std::endl | |
| }; |
This file contains hidden or 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
| template <int Begin, int End, int Size, class Enable=void> | |
| struct partition; | |
| template <int BeginIt, int EndIt, int Size> | |
| struct partition<BeginIt, EndIt, Size, typename std::enable_if<(BeginIt<EndIt)>::type> { | |
| template <class T> | |
| inline static void go(T* vec, const T& pivot) { | |
| if (vec[BeginIt] <= pivot) { |
This file contains hidden or 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
| std::auto_ptr<int> a( new int ), | |
| b( new int ); | |
| *a = *b = 0; | |
| a = b; | |
| *b; // SEGFAULT |
This file contains hidden or 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 <vector> | |
| class Instance { | |
| const Instance* ref; | |
| int value; | |
| public: | |
| Instance (const Instance* other, int value) : | |
| ref(ref), value(value) { } | |
| }; |
This file contains hidden or 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 <vector> | |
| #include <memory> | |
| class Instance { | |
| std::shared_ptr<const Instance> ref; | |
| int value; | |
| public: | |
| Instance (const std::shared_ptr<const Instance>& other, int value) : | |
| ref(other), value(value) { } |
This file contains hidden or 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 <memory> | |
| class Instance { | |
| std::weak_ptr<const Instance> ref; | |
| int value; | |
| public: | |
| Instance (const std::shared_ptr<const Instance>& other, int value) : | |
| ref(other), value(value) { } | |
| void setRef(const std::shared_ptr<const Instance>& ref) { |
This file contains hidden or 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 <tuple> | |
| #include <numeric> | |
| #include <vector> | |
| #include <string> | |
| namespace detail { | |
| template <class T> | |
| struct get_size_helper; |
This file contains hidden or 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 <tuple> | |
| #include <numeric> | |
| #include <vector> | |
| #include <string> | |
| // forward declaration of get_size() method | |
| template <class T> | |
| size_t get_size(const T& obj); | |
| namespace detail { |
This file contains hidden or 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 <gtest/gtest.h> | |
| #include "utils/serialize.h" | |
| TEST(get_size, Ints) { | |
| uint16_t v1 = 2u; | |
| EXPECT_EQ(sizeof(decltype(v1)), get_size(v1)); | |
| EXPECT_EQ(2u, get_size(v1)); | |
| uint32_t v2 = 10u; | |
| EXPECT_EQ(sizeof(decltype(v2)), get_size(v2)); |
This file contains hidden or 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
| namespace detail { | |
| template <class T> | |
| class serialize_helper; | |
| template <class T> | |
| void serializer(const T& obj, StreamType::iterator&); | |
| template <class tuple_type> | |
| inline void serialize_tuple(const tuple_type& obj, StreamType::iterator& res, int_<0>) { |