c++11

#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <functional>
#include <random>

using namespace std::placeholders;

constexpr int getnum() { return 10;}
int arr[getnum()];

struct Foo
{
void print_sum(int n1, int n2)
{
std::cout << n1 << " " << n2 << '\n';
}
int data = 10;
};
int fnc(int a, const int &b, int &c)
{
std::cout << a << " " << b << " " << c << std::endl;
}

void test()
{
// // init list
// std::vector<int> iv {0, 1, 2};
// iv.push_back(3);
//
// // rvalue ref
// std::vector<int> iv1 = std::move(iv);
// std::cout << iv.empty() << std::endl;
// std::cout << iv1.size() << std::endl;
// // range based for
// for (int &i : iv1)
// std::cout << i << " " ;
// std::cout << std::endl;
//
//
// // bind to a member function
// Foo foo;
// auto f1 = std::bind(&Foo::print_sum, foo, 95, _1);
// f1(5);
//
// // bind a function
// int a = 1;
// int b = 2;
// int c = 3;
//
// auto f2 = std::bind(fnc, _1, b, c);
// f2(1);
//
// c = 4;
// f2(1);
//
// auto f3 = std::bind(fnc, _1, b, std::ref(c));
// c++;
// f3(1);
// // decltype
// int someInt;
// decltype(someInt) otherInt = 1;
//
// // lambda
// auto l1 = [](int x, int y) { return x + y; }
// std::cout << l1(1, 3) << std::endl;
//
int inum = 4;
int inum1 = 4;
int inum2 = 4;
auto l2 = [&](int x)
{
inum1++;
inum2++;
inum++;
};
l2(1);
std::cout << inum << " " << inum1 << " " << inum2 << std::endl;

}

int main()
{
test();
return 0;
}

原文地址:https://www.cnblogs.com/threef/p/3011925.html