1->创建7个Thread,跑个非常大的循环.观察CPU

  1. void func(string &name)
  2. {
  3. for(auto i=;i<0xFFFFFFFF;i++)
  4. {
  5. //cout << name << this_thread::get_id() << "running \n";
  6. }
  7. }
  8. int main()
  9. {
  10. string thread_01_name("AThread");
  11. string thread_02_name("BThread");
  12. string thread_03_name("CThread");
  13. string thread_04_name("DThread");
  14. string thread_05_name("EThread");
  15. string thread_06_name("FThread");
  16. string thread_07_name("HThread");
  17.  
  18. thread thread_01(func,ref(thread_01_name));
  19. thread thread_02(func,ref(thread_02_name));
  20. thread thread_03(func,ref(thread_03_name));
  21. thread thread_04(func,ref(thread_04_name));
  22. thread thread_05(func,ref(thread_05_name));
  23. thread thread_06(func,ref(thread_06_name));
  24. thread thread_07(func,ref(thread_07_name));
  25.  
  26. thread_01.join();
  27. thread_02.join();
  28. thread_03.join();
  29. thread_04.join();
  30. thread_05.join();
  31. thread_06.join();
  32. thread_07.join();
  33.  
  34. }

2->Mutex

  1. static int globNum = ;
  2. mutex g_lock;
  3. void func()
  4. {
  5. g_lock.lock();
  6. std::cout << " going to in thread ID " << std::this_thread::get_id() << std::endl;
  7. std::this_thread::sleep_for((std::chrono::seconds()));
  8. std::cout << " leaving thread ID " << std::this_thread::get_id() << std::endl;
  9. globNum += ;
  10. g_lock.unlock();
  11. }
  12. int main()
  13. {
  14.  
  15. std::thread t1(func);
  16. std::thread t2(func);
  17. std::thread t3(func);
  18.  
  19. t1.join();
  20. t2.join();
  21. t3.join();
  22.  
  23. cout << globNum << endl;
  24. return ;
  25. }

3->

4->容器类

  1. vector <int> test;
  2. test.push_back();
  3. test.push_back();
  4. for(auto &e : test )
  5. {
  6. cout << e <<endl;
  7. }

5,memset,lambda

  1. #include <iostream>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <vector>
  5.  
  6. struct table
  7. {
  8. int age;
  9. char name[];
  10. int arr[];
  11. };
  12.  
  13. int main()
  14. {
  15.  
  16. char buffer[]="hello";
  17. std::cout << "buffer is " << buffer <<std::endl;
  18.  
  19. char buffer2[] = "dest";
  20. memcpy(buffer,buffer2,);
  21. std::cout << "after memcpy is " << buffer <<std::endl;
  22.  
  23. memset(buffer,'*',strlen(buffer));
  24. std::cout << "after memset is " << buffer <<std::endl;
  25.  
  26. int intBuffer[] ={,,,,};
  27. memset(intBuffer,,sizeof(int)*);
  28. for(const auto &n:intBuffer)
  29. {
  30. std::cout <<"memset int buffer" <<n << std::endl;
  31. }
  32.  
  33. double doubleBuffer[]={1.0,2.0,3.0,4.0,5.0};
  34. memset(doubleBuffer,,sizeof(double)*); // set all double buffer inside is 0
  35. for(const auto&n: doubleBuffer)
  36. {
  37. std::cout << "double buffer is " << n <<std::endl;
  38. }
  39.  
  40. int a =;
  41. int b =;
  42. std::swap(a,b);
  43. std::cout << "A:" <<a <<" B:" <<b <<std::endl;
  44.  
  45. table ta;
  46. ta.age = ;
  47. strcpy(ta.name,"houdini");
  48. memset(ta.arr,,sizeof(int)*);
  49.  
  50. table tb;
  51. tb.age = ;
  52. strcpy(tb.name,"maya");
  53. memset(tb.arr,,sizeof(int)*);
  54.  
  55. std::cout << "ta " <<ta.age << " " << ta.name <<std::endl;
  56. std::cout << "tb " <<tb.age << " " << tb.name <<std::endl;
  57.  
  58. std::cout << "swap struct \n";
  59. std::swap(ta,tb);
  60. std::cout << "ta " <<ta.age << " " << ta.name <<std::endl;
  61. std::cout << "tb " <<tb.age << " " << tb.name <<std::endl;
  62.  
  63. // [] define the lambda , () is the arg
  64. // [captures] (params) -> ret {Statments;}
  65. std::cout << "\nlambda \n";
  66. auto func = []() { std::cout << "Hello world"; };
  67. func(); // now call the function
  68.  
  69. std::vector<int> v;
  70. v.push_back();
  71. v.push_back();
  72. v.push_back();
  73. std::for_each(std::begin(v), std::end(v), [](int n) {std::cout << n << std::endl;});
  74.  
  75. std::cout << "Make a lambda function \n";
  76. auto is_odd = [](int n) {return n+;};
  77. std::cout << is_odd() <<std::endl;
  78.  
  79. std::function<int(int)> func2 = [](int i) { return i+; };
  80. std::cout << "func2: " << func2() << '\n';
  81.  
  82. return ;
  83. }

6,匿名指向函数指针:

  1. int printadd(int x,int y)
  2. {
  3. std::cout << "x y :" << x << " | " << y<<std::endl;
  4. return x+y;
  5. }
  6.  
  7. int main()
  8. {
  9. typedef int (*callBack)(int x,int y);
  10. auto will_callBack = [](callBack callBackParm,int x,int y)
  11. {
  12. return callBackParm(x,y);
  13.  
  14. };
  15. std::cout << will_callBack(printadd,,) <<std::endl;
  16.  
  17. return ;
  18. }

7,变长参数,C和C++

C:

  1. int* AllocateArray(int count, ...)
  2. {
  3. int *p = static_cast<int*> (malloc(sizeof(int)*count));
  4. va_list args;
  5. va_start(args, count);
  6. for (int i = ; i < count; ++i)
  7. {
  8.  
  9. int arg = va_arg(args, int);
  10. *(p+i) = arg;
  11.  
  12. }
  13. va_end(args);
  14. return p;
  15. }
  16.  
  17. void DestroyArray(int *p)
  18. {
  19. free(p);
  20. }
  21.  
  22. int main()
  23. {
  24.  
  25. int *p = AllocateArray(,,,,,);
  26. auto lm = [](int *p,int size)
  27. {
  28. for(int i=;i<size;i++)
  29. {
  30. std::cout << p[i] <<std::endl;
  31. }
  32. };
  33.  
  34. lm(p,);
  35. DestroyArray(p);
  36. }

C++

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // end of call for 0 parameters
  5. void show_list() {}
  6.  
  7. // we just transfer the ref
  8. template <typename T>
  9. void show_list(const T &value)
  10. {
  11. cout << value <<" eof" << endl;
  12. }
  13.  
  14. template <typename T ,typename... Args>
  15. void show_list(const T &value ,const Args&... args)
  16. {
  17. cout << value << ",";
  18. show_list(args...);
  19. };
  20.  
  21. int main()
  22. {
  23. show_list("",,,,);
  24. show_list("",,,,);
  25. return ;
  26. }

8,模板函数.

基本概念:

(1):显式实例化(explicit instantiation)

template class ArrayTP<string,100> ;// generate ArrayTP<string,100> class

(2):显式具体化(explicit specialization)

  1. template<>
  2.  
  3. class ClassName<specialized-type-name>
  4.  
  5. {...}

(3):部分具体化(partial specialization)

  1. template <class T1,class T2>
  2. class Pair
  3. {
  4. //...
  5. };
  6.  
  7. template <class T1>
  8. class Pair<T1,int>
  9. {
  10. //...
  11. };

当参数和模板都一致,类似以下形式:

1,

  1. template <typename T>
  2. inline T add(T x,T y)
  3. {
  4. return x+y;
  5. }
  6. int main()
  7. {
  8. std::cout << add(,) <<std::endl;
  9. std::cout << add(1.0f,2.0f) <<std::endl;
  10. //std::cout << add(1.0f,2) <<std::endl; //ERROR
  11. std::cout << add<int>(1.01,) <<std::endl;
  12. std::cout << add<double>(1.01,) <<std::endl;
  13. std::cout << add<float>(1.11f,) <<std::endl;
  14. return ;
  15. }

2,显式模板定义,当返回值是模板,但是参数不是模板:

  1. struct Data
  2. {
  3. int val;
  4. };
  5. template <typename ValueType>
  6. inline ValueType addOne(int val)
  7. {
  8. std::cout << "go to addOne default template ";
  9. return ValueType(val) + ValueType();
  10. }
  11.  
  12. template <>
  13. inline float addOne<float>(int val)
  14. {
  15. std::cout << "go to addOne <float> ";
  16. return float(val) + float();
  17. }
  18. template <>
  19. inline Data addOne<Data> (int val)
  20. {
  21. std::cout << "go to addOne <Data> struct";
  22. Data x;
  23. x.val = val + ;
  24. return x;
  25. }
  26.  
  27. inline std::ostream &operator<<(std::ostream &os,Data rh)
  28. {
  29. os << rh.val <<std::endl;
  30. return os;
  31. }
  32.  
  33. int main()
  34. {
  35. Data x = {};
  36. std::cout << addOne<int>() << std::endl; // default template
  37. std::cout << addOne<float>() <<std::endl;
  38. std::cout << addOne<Data>() <<std::endl;
  39.  
  40. return ;
  41. }

9,std::shared_ptr<> 智能指针.

  1. #include <iostream>
  2. #include <memory>
  3. #include <string>
  4.  
  5. //template <typename Data>
  6. class Test
  7. {
  8. public:
  9. Test():mName("NULL NAME")
  10. {
  11. std::cout <<"Create Test\n";
  12. }
  13. Test(std::string name)
  14. {
  15. mName = name;
  16. }
  17. void printName()
  18. {
  19. std::cout << "name is : " << mName <<std::endl;
  20. }
  21. void setName(std::string name)
  22. {
  23. mName = name;
  24. }
  25. ~Test(){
  26. std::cout <<mName<< " Test destroyed\n";
  27. }
  28. //using Ptr = std::shared_ptr<Test>;
  29. typedef std::shared_ptr<Test> Ptr;
  30. private:
  31. std::string mName;
  32. };
  33.  
  34. int main()
  35. {
  36. std::cout << "Hello, World!" << std::endl;
  37. Test::Ptr test(new Test("Houdini"));
  38. test->printName();
  39. Test::Ptr test2 = test;
  40. test2->setName("maya");
  41. test2->printName();
  42. std::cout << test2.use_count() <<std::endl; //
  43. test2.reset();
  44. // test2 can't access
  45. std::cout << test.use_count() <<std::endl; //
  46. return ;
  47. }

10,迭代器:

(1) 基于C++11 的forloop

  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. void showValue(int x)
  6. {
  7. cout << x <<endl;
  8. }
  9.  
  10. template <typename iter,typename func>
  11. func Navie_foreach(iter first,iter end,func f)
  12. {
  13. for(;first!=end;++first)
  14. {
  15. f(*first);
  16. }
  17. return std::move(f);
  18. };
  19.  
  20. int main()
  21. {
  22. vector<int> list;
  23. list.push_back();
  24. list.push_back();
  25. list.push_back();
  26.  
  27. cout << "use algorithm \n";
  28. for_each(list.begin(),list.end(),showValue);
  29.  
  30. cout << "use my function \n";
  31. Navie_foreach(list.begin(),list.end(),showValue);
  32.  
  33. cout << "use for(auto x: list) \n";
  34. for(auto x: list)
  35. {
  36. showValue(x);
  37. }
  38.  
  39. return ;
  40. }

(2)自定义一个简单的CStringIter

  1. class CStrIter
  2. {
  3. private:
  4. char **next;
  5. public:
  6. CStrIter():next(){
  7. }
  8. CStrIter(char **text)
  9. {
  10. next = text;
  11. }
  12. const char* operator*()
  13. {
  14. return *next;
  15. }
  16. CStrIter &operator++() // for ++it
  17. {
  18. next = next+;
  19. return *this;
  20. }
  21. bool operator!=(void *data)
  22. {
  23. return *next != NULL;
  24. }
  25.  
  26. };
  27.  
  28. int main()
  29. {
  30. char *menu[]= {"Houdini","Maya",NULL};
  31. CStrIter iter(menu);
  32. for(; iter!=NULL;++iter)
  33. {
  34. cout << *iter <<endl;
  35. }
  36.  
  37. }

(3)自定义一个简单的超尾迭代器

  1. #include <iostream>
  2. #include <iterator>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. template <typename T>
  9. void dpelement(T i)
  10. {
  11. cout << "->" << i <<endl;
  12. }
  13. template<>
  14. void dpelement<int>(int i)
  15. {
  16. cout << "int ->" << i <<endl;
  17. }
  18. void unit_test_foreach()
  19. {
  20. const int size = ;
  21. int app[size]= {,,,};
  22. vector<int> dice(size);
  23. copy(app,app+size,dice.begin());
  24. for_each(dice.begin(),dice.end(),dpelement<int>);
  25. }
  26.  
  27. template <typename T>
  28. struct ourArray
  29. {
  30.  
  31. public:
  32. class Iter
  33. {
  34. public:
  35. Iter():mHandle(),mArrayIndex(){
  36.  
  37. }
  38. Iter(T *IterFirst):mHandle(IterFirst),mArrayIndex()
  39. {
  40.  
  41. }
  42. Iter &operator=(T *data)
  43. {
  44. mHandle = data;
  45. return *this;
  46. }
  47.  
  48. Iter& operator++() // for ++it
  49. {
  50. mHandle = mHandle+;
  51. mArrayIndex += ;
  52. return *this;
  53. }
  54. T &operator*() // *it is our value
  55. {
  56. return *mHandle;
  57. }
  58. bool operator!=(T *data)
  59. {
  60. return mHandle != data ;
  61. }
  62. void next()
  63. {
  64. mHandle += ;
  65. mArrayIndex +=;
  66. }
  67. int index()const
  68. {
  69. return mArrayIndex;
  70. }
  71.  
  72. private:
  73. T *mHandle;
  74. unsigned int mArrayIndex ;
  75. };
  76.  
  77. public:
  78. ourArray(int length)
  79. {
  80. mArray = new T[length + ];
  81. for(int i=;i<length;i++)
  82. {
  83. mArray[i] = T(i+);
  84. }
  85. // define a eof signals
  86. mArray[length] = 0xFFFFFFFF;
  87. _size = length;
  88. }
  89. ~ourArray()
  90. {
  91. delete []mArray;
  92. mArray = nullptr;
  93. }
  94. void clear()
  95. {
  96. delete []mArray;
  97. mArray = nullptr;
  98. }
  99. T *begin()
  100. {
  101. return mArray;
  102. }
  103. T *end()
  104. {
  105. return mArray+(_size);
  106. }
  107. int operator[](int i)
  108. {
  109. return mArray[i];
  110. }
  111. unsigned int size()const
  112. {
  113. return _size;
  114. }
  115. const Iter ConstIter()
  116. {
  117. ourArray<T>::Iter iter;
  118. iter = array.begin();
  119. return iter;
  120. }
  121.  
  122. private:
  123. unsigned int _size;
  124. T *mArray;
  125. };
  126.  
  127. int main()
  128. {
  129. ourArray<float> array();
  130. ourArray<float>::Iter iter;
  131. for(iter=array.begin();iter!=array.end();++iter)
  132. {
  133. cout << " INDEX: " <<iter.index() << " Of value: " <<*iter <<endl;
  134.  
  135. }
  136. cin.get();
  137. return ;
  138.  
  139. }

(4)

ostream_iterator,fill,copy

  1. ostream_iterator <int,char> out_iter(cout,"\n");
  2.  
  3. *out_iter++ = ; //same as cout<<15 << "\n"
  4. *out_iter = ;
  5.  
  6. // STL copy vector to out_iter
  7. vector <int> data();
  8. fill(data.begin(),data.end(),); // fill 1 to array
  9. copy(data.begin(),data.end(),out_iter); // print 1 six times
  10.  
  11. cout << "\n";
  12. copy(data.begin(),data.end(),ostream_iterator<int,char>(cout,"->"));
  13. cout << "\n";

istream_iterator

  1. int val = ;
  2. auto inputStr_iter = istream_iterator<int,char>(cin);
  3. val = *inputStr_iter;
  4. cout << "type value is " << val <<endl;

copy

  1. template <typename T>
  2. void dpelement(T i)
  3. {
  4. cout << "->" << i <<endl;
  5. }
  6. template<>
  7. void dpelement<int>(int i)
  8. {
  9. cout << "int ->" << i <<endl;
  10. }
  11.  
  12. string s1[] = {"good","wife","good","life"};
  13. vector<string> s1_t();
  14. copy(s1,s1+,s1_t.begin());
  15. for_each(s1_t.begin(),s1_t.end(),dpelement<string>);
  16.  
  17. const int size = ;
  18. int app[size]= {,,,};
  19. vector<int> dice(size);
  20. copy(app,app+size,dice.begin());
  21. for_each(dice.begin(),dice.end(),dpelement<int>);

list

  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <list>
  5. using namespace std;
  6. template <typename T>void showValue(T x)
  7. {
  8. cout << x <<endl;
  9. }
  10.  
  11. template <typename container,typename valueType>
  12. void showContainerValue(const char*containerName, const container &con)
  13. {
  14. cout <<"------"<< containerName <<"------\n";
  15. for_each(con.begin(),con.end(),showValue<valueType>);
  16. cout <<"------"<< containerName <<"------\n\n";
  17. };
  18.  
  19. int main()
  20. {
  21. list<int> one(,);
  22. showContainerValue<list<int>,int>("one",one);
  23.  
  24. int stuff[] = {,,,,,,};
  25. list<int> two;
  26. two.insert(two.begin(),stuff,stuff+);
  27. showContainerValue<list<int>,int>("two",two);
  28.  
  29. two.sort();
  30. showContainerValue<list<int>,int>("two after sort",two);
  31.  
  32. two.unique();
  33. showContainerValue<list<int>,int>("two after unique",two);
  34.  
  35. cin.get();
  36.  
  37. return ;
  38. }

set,set_union,set_difference,set_intersection (set里的元素不会重复,即使插入重复的。,set会自动排序,所以有可能顺序跟insert顺序不一样)

  1. #include <set>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <iterator>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int nq_array[] = {,,,,,};
  10. set<int> unique_mapsA(nq_array,nq_array+);
  11. set<int>::iterator start = unique_mapsA.begin();
  12. unique_mapsA.insert();
  13. unique_mapsA.insert();
  14. unique_mapsA.insert();
  15.  
  16. for(;start!=unique_mapsA.end();start++)
  17. {
  18. cout << *start <<endl;
  19. }
  20.  
  21. set<int> unique_mapsB;
  22. unique_mapsB.insert();
  23. unique_mapsB.insert();
  24.  
  25. set<int> unique_mapsC;
  26.  
  27. // set_union()
  28. // set_difference()
  29. // set_intersection()
  30. set_intersection(unique_mapsA.begin(),unique_mapsA.end(),unique_mapsB.begin(),unique_mapsB.end(),
  31. insert_iterator<set<int>>(unique_mapsC,unique_mapsC.begin()));
  32.  
  33. set<int>::iterator cIter;
  34. cout << "set_intersection\n";
  35. for(cIter=unique_mapsC.begin();cIter!= unique_mapsC.end(); cIter++)
  36. {
  37. cout << *cIter <<endl;
  38. }
  39. cin.get();
  40. return ;
  41.  
  42. }

set对ostream_iterator<int,char>out(cout,"\n")

  1. cout << "ostream_iterator print set data\n";
  2. ostream_iterator<int,char> out(cout,"\n");
  3. copy(unique_mapsB.begin(),unique_mapsB.end(),out);

(5)multimap,pair (multimap的key 可以是重复的)

包括如何取出重复的键元素

  1. #include <map>
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. typedef multimap<int,string> mm;
  7. typedef pair<int,string> mp;
  8.  
  9. template <typename T>
  10. void printData(T &cont)
  11. {
  12. auto iter = cont.begin();
  13. for(;iter!=cont.end();iter++)
  14. {
  15. cout << *iter <<endl;
  16. }
  17. }
  18. // specialize our multimap<int,string>
  19. template <>
  20. void printData<mm>(mm &cont)
  21. {
  22. auto iter = cont.begin();
  23. for(;iter!=cont.end();iter++)
  24. {
  25. cout << "key:"<<(*iter).first << " -> value:"<<(*iter).second <<endl;
  26. }
  27. }
  28.  
  29. int main()
  30. {
  31. mm codes;
  32. mp item(,"maya");
  33. codes.insert(item);
  34. codes.insert(mp(,"houdini"));
  35. codes.insert(mp(,"json"));
  36. printData(codes);
  37.  
  38. // isolate 213 data
  39. cout << "\nisolate 213 data\n";
  40. pair<mm::iterator,mm::iterator> range = codes.equal_range();
  41. for(mm::iterator it = range.first; it!=range.second; ++it)
  42. {
  43. cout << (*it).first << "->"<<(*it).second <<endl;
  44. }
  45. cin.get();
  46. return ;
  47.  
  48. }

9,函数对象

list,list->insert(),list.remove_if()

  1. #include <iostream>
  2. #include <list>
  3. #include <algorithm>
  4. #include <iterator>
  5.  
  6. template <typename T_C,typename valType>
  7. void showArrayVals(T_C &cont,const char* contName)
  8. {
  9. ostream_iterator<valType,char> out(cout,"\n");
  10. cout << "----------" << contName << "----------\n";
  11. for(auto iter = cont.begin();iter!=cont.end();iter++)
  12. {
  13. *out++ = *iter;
  14. }
  15. cout << "----------" << contName << "----------\n";
  16. }
  17.  
  18. template <typename T>class TooBig
  19. {
  20. private:
  21. T cutoff;
  22. public:
  23. TooBig(const T&cut):cutoff(cut){
  24.  
  25. }
  26. bool operator()(const T& v){return v>cutoff;}
  27. };
  28.  
  29. using namespace std;
  30.  
  31. int main()
  32. {
  33. TooBig<int> b100();
  34. list<int> vals;
  35. vals.insert(vals.begin(),);
  36.  
  37. list<int>::iterator it = vals.begin(); // first element
  38. ++it;
  39. vals.insert(it,); // array [1,2]
  40. --it;
  41. vals.insert(it,,); // array [1,10,10,2]
  42. vals.insert(it,,); // array [1,10,10,3,2]
  43. vals.insert(it,,); // array [1,10,10,3,5,2]
  44. showArrayVals<list<int>,int>(vals,"vals container");
  45. vals.remove_if(b100); // remove greater 9
  46. showArrayVals<list<int>,int>(vals,"after remove vals > 9 container");
  47.  
  48. vals.remove_if(TooBig<int>()); // remove greater 4
  49. showArrayVals<list<int>,int>(vals,"after remove vals > 4 container");
  50.  
  51. cin.get();
  52. return ;
  53. }

10,STL string,map,set ,匿名函数

  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4. #include <iterator>
  5. #include <algorithm>
  6. #include <map>
  7. #include <set>
  8. using namespace std;
  9.  
  10. template <typename T>
  11. void showMap(T &mm)
  12. {
  13. T::const_iterator iter;
  14. for(iter=mm.begin();iter!=mm.end();iter++)
  15. {
  16. cout << "Key:"<<(*iter).first << " val:" << (*iter).second <<endl;
  17. }
  18. }
  19.  
  20. char chToLower(char ch){
  21. return tolower(ch);
  22. }
  23.  
  24. string &StrToLower(string &st)
  25. {
  26. transform(st.begin(),st.end(),st.begin(),chToLower);
  27. return st;
  28. }
  29.  
  30. // function convert map's value to a set,and convert to lower char
  31. template <typename T1,typename T2>
  32. void mapToSet(T1 &rhMap,T2 &rhSet)
  33. {
  34. T1::const_iterator iter;
  35. for(iter=rhMap.begin();iter!=rhMap.end();iter++)
  36. {
  37. string item = (*iter).second;
  38. StrToLower(item);
  39. rhSet.insert(item);
  40. }
  41. }
  42.  
  43. // show container's value
  44. template<typename cont,typename valType>
  45. void showContainerValues(cont &cc)
  46. {
  47. //for_each(begin(cc), end(cc), [](valType n) {std::cout << n << std::endl;});
  48. for_each(cc.begin(),cc.end(),
  49. [](valType n) {std::cout << n << std::endl;}
  50. );
  51. }
  52.  
  53. int main()
  54. {
  55. map<int,string> ids;
  56. ids.insert(pair<int,string>(,"ADMIN"));
  57. ids.insert(pair<int,string>(,"ADMIN2")); // do not accept repeat key
  58. ids.insert(pair<int,string>(,"SUPER"));
  59. ids.insert(pair<int,string>(,"HOUDINI"));
  60. ids.insert(pair<int,string>(,"NUKE"));
  61.  
  62. ids[] = "MASTER"; // map can use [] anywhere
  63.  
  64. showMap(ids);
  65.  
  66. //
  67. cout << "\ninsert all map to set\n";
  68. set<string> wordset;
  69. mapToSet<>(ids,wordset);
  70. showContainerValues<set<string>,string>(wordset);
  71.  
  72. cin.get();
  73. return ;
  74. }

11

C++ 11 snippets , 1的更多相关文章

  1. C++ 11 snippets , 2

    <1>auto ,initializer_list<T>,auto指向函数指针的简易,和typdef 定义的类型执行函数指针有多复杂. #include <iostrea ...

  2. Visual Studio 2010 中的 Web 开发

    概述 Microsoft Visual Studio 2010 为 ASP.NET Web 应用程序的开发提供非常多新的功能.这些新功能旨在帮助开发者高速方便地创建和部署质量高且功能全的 Web 应用 ...

  3. [OpenCV] Install OpenCV 3.4 with DNN

    目标定位 一.开始全面支持 Tensorflow OpenCV3.4 新功能 当前最新进展OpenCV 3.4 dev:https://github.com/opencv/opencv/tree/ma ...

  4. 地区sql

    /*Navicat MySQL Data Transfer Source Server : localhostSource Server Version : 50136Source Host : lo ...

  5. 25+ Useful Selenium Web driver Code Snippets For GUI Testing Automation

    本文总结了使用Selenium Web driver 做页面自动化测试的一些 tips, tricks, snippets. 1. Chrome Driver 如何安装 extensions 两种方式 ...

  6. Java 9 揭秘(11. Java Shell)

    Tips 做一个终身学习的人. 在本章节中,主要介绍以下内容: 什么是Java shell JShell工具和JShell API是什么 如何配置JShell工具 如何使用JShell工具对Java代 ...

  7. 11月26号host

    127.0.0.1 localhost255.255.255.255 broadcasthost::1 localhostfe80::1%lo0 localhost # Google start216 ...

  8. 11月16host文件

    #################################################################################################### ...

  9. c++ telescoping constructor is NOT supported until c++11

    Telescoping constructor: see Effective Java 2nd Edition Item 2 If you want to use telescoping constr ...

随机推荐

  1. js 各种事件 如:点击事件、失去焦点、键盘事件等

    事件驱动:        我们点击按钮 按钮去掉用相应的方法.                demo:             <input type="button" v ...

  2. ECharts基础

    echarts: js引用:<script type="text/javascript" src="js/echarts.js"></scri ...

  3. ipv4转化为ipv6

    十進制轉換成十六進位 IPV6為十六進位,所以十進制轉換成十六進位192=c0 168=a8192.168.1.1 轉成 16 進制為 c0.a8.01.01可以使用 Windows 工程版或是程式設 ...

  4. Hbase学习02

    第2章 Apache HBase配置 本章在“入门”一章中进行了扩展,以进一步解释Apache HBase的配置. 请仔细阅读本章,特别是基本先决条件,确保您的HBase测试和部署顺利进行,并防止数据 ...

  5. java中用jdom创建xml文档/将数据写入XML中

    import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; i ...

  6. Linux记录-使用python临时搭建web服务器

    python2: python -m SimpleHTTPServer 8888 python3: python -m http.server 8888 wget   ip:8888/文件

  7. Linux拉你入门

    前言:为了做一个更优秀的程序猿,Linux是必不可少的,因此利用闲杂的时间来增加自己对Linux的认识 (一)关于Linux命令编(至于怎样安装vmvare这一个章节就先不介绍了) 1.基础命令 1. ...

  8. Understanding Favicon

    Favicon 简介 Favicon : 是favorites icon 的缩写,被称为website icon . page icon. urlicon. 最初定义一个favicon的方法是将一个名 ...

  9. 让Windows Server 2008r2 IIS7.5 ASP.NET 支持10万并发请求

    由于之前使用的是默认配置,服务器最多只能处理5000个同时请求,今天下午由于某种情况造成同时请求超过5000,从而出现了上面的错误. 为了避免这样的错误,我们根据相关文档调整了设置,让服务器从设置上支 ...

  10. 11-SQLServer的事务、存储过程和触发器

    一. 事务 在SQLServer中,每条SQL语句,默认就是一条隐式的事务,但是如果我们需要一组SQL语句,那么就需要采用SQLServer提供的特有的标记 来声明事务的开始.提交和回滚了. 事务的开 ...