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
| int a = 5; | |
| decltype(a) b = a; |
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
| decltype(4+3+a) b = 4+3+a; |
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
| auto b = 4+3+a; |
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
| typedef std::pair<int,double> KeyObj; | |
| bool my_cmp(const KeyObj& lhs, const KeyObj& rhs) { | |
| return (lhs.first < rhs.first) || | |
| ((lhs.first == rhs.first) && (lhs.second < rhs.second)); | |
| } | |
| std::set<KeyObj, bool (*)(const KeyObj&, const KeyOnk&)> my_set(my_cmp); | |
| my_set.insert( { 2, 3.4f } ); |
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
| typedef std::pair<int,double> KeyObj; | |
| struct my_cmp { | |
| bool operator()(const KeyObj& lhs, const KeyObj& rhs) const { | |
| return (lhs.first < rhs.first) || | |
| ((lhs.first == rhs.first) && (lhs.second < rhs.second)); | |
| } | |
| }; | |
| std::set<KeyObj, my_cmp> my_set; | |
| my_set.insert( { 2, 3.4f } ); |
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
| typedef std::pair<int,double> KeyObj; | |
| auto my_cmp = [] (const KeyObj& lhs, const KeyObj& rhs) -> bool { | |
| return (lhs.first < rhs.first) || | |
| ((lhs.first == rhs.first) && (lhs.second < rhs.second)); | |
| }; | |
| std::set<KeyObj, decltype(my_cmp)> my_set(my_cmp); | |
| my_set.insert( { 2, 3.4f } ); |
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
| auto t1 = std::make_tuple( 10, 3.4f, "awesomeness" ); | |
| std::tuple<const int&, int> t2{ std::cref(std::get<0>(t1)), 20 }; | |
| auto t3 = std::tie( std::get<0>(t1), std::get<1>(t2) ); | |
| std::get<0>(t3) = 2; | |
| assert( (std::get<0>(t1) == 2) && (std::get<0>(t2) == 2) && (std::get<0>(t3) == 2) ); |
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
| // Define a type which holds an unsigned integer value | |
| template<std::size_t> struct int_{}; | |
| template <class Tuple, size_t Pos> | |
| std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos> ) { | |
| out << std::get< std::tuple_size<Tuple>::value-Pos >(t) << ','; | |
| return print_tuple(out, t, int_<Pos-1>()); | |
| } | |
| template <class Tuple> |
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::cout << t1 << std::endl; // => (2,3.4f,"awesomeness") | |
| std::cout << t2 << std::endl; // => (2,20) | |
| std::cout << t3 << std::endl; // => (2,20) |
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
| auto f = std::unary_negate<int>() >> [](int c) -> int {return c*c;}; | |
| std::cout << f(4) << std::endl; // => -16 |
OlderNewer