diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ee4f826065528b02cd5565698a1fc9d598676d0a --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# 排除常见的二进制文件扩展名 +*.exe +*.dll +*.so +*.a +*.o +*.bin +*.dat +*.class +*.pyc +*.jar +*.war +*.ear + +# 排除特定目录中的二进制文件 +build/**/*.{exe,dll,so,bin} +bin/**/*.{exe,dll,so,bin} +demo/**/*.{exe,dll,so,bin} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0efcefa328bbe05ecb0e2e8bd4f0019ae00486aa --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.10) +project(StlFuncs) + +# 设置 C++ 标准 +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +# 启用测试功能 +enable_testing() + +# 设置输出路径 +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib64) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib64) + +# 添加头文件目录 +include_directories(include) + +# 添加子目录 +add_subdirectory(src) +add_subdirectory(tests) \ No newline at end of file diff --git a/algo/fill1.cpp b/algo/fill1.cpp deleted file mode 100644 index 5e60c27ac811a605c6e2ca29b9836feb8ba9dde4..0000000000000000000000000000000000000000 --- a/algo/fill1.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* The following code example is taken from the book - * "The C++ Standard Library - A Tutorial and Reference, 2nd Edition" - * by Nicolai M. Josuttis, Addison-Wesley, 2012 - * - * (C) Copyright Nicolai M. Josuttis 2012. - * Permission to copy, use, modify, sell and distribute this software - * is granted provided this copyright notice appears in all copies. - * This software is provided "as is" without express or implied - * warranty, and with no claim as to its suitability for any purpose. - */ -#include "algostuff.hpp" -using namespace std; - -int main() -{ - // print ten times 7.7 - fill_n(ostream_iterator(cout, " "), // beginning of destination - 10, // count - 7.7); // new value - cout << endl; - - list coll; - - // insert "hello" nine times - fill_n(back_inserter(coll), // beginning of destination - 9, // count - "hello"); // new value - PRINT_ELEMENTS(coll,"coll: "); - - // overwrite all elements with "again" - fill(coll.begin(), coll.end(), // destination - "again"); // new value - PRINT_ELEMENTS(coll,"coll: "); - - // replace all but two elements with "hi" - fill_n(coll.begin(), // beginning of destination - coll.size()-2, // count - "hi"); // new value - PRINT_ELEMENTS(coll,"coll: "); - - // replace the second and up to the last element but one with "hmmm" - list::iterator pos1, pos2; - pos1 = coll.begin(); - pos2 = coll.end(); - fill (++pos1, --pos2, // destination - "hmmm"); // new value - PRINT_ELEMENTS(coll,"coll: "); -} diff --git a/README b/demo/README similarity index 100% rename from README rename to demo/README diff --git a/algo/copy1.cpp b/demo/algo/accumulate1.cpp similarity index 33% rename from algo/copy1.cpp rename to demo/algo/accumulate1.cpp index 21728affca4b4cbc6271cb2b276b397b1116d2b6..5af6e2a0ac261efd98b4f4a342f27159e8d21361 100644 --- a/algo/copy1.cpp +++ b/demo/algo/accumulate1.cpp @@ -11,29 +11,39 @@ #include "algostuff.hpp" using namespace std; -int main() -{ - vector coll1 = { "Hello", "this", "is", "an", "example" }; - list coll2; +int main() { + vector coll; - // copy elements of coll1 into coll2 - // - use back inserter to insert instead of overwrite - copy (coll1.cbegin(), coll1.cend(), // source range - back_inserter(coll2)); // destination range + INSERT_ELEMENTS(coll, 1, 9); + PRINT_ELEMENTS(coll); + // 1 2 3 4 5 6 7 8 9 - // print elements of coll2 - // - copy elements to cout using an ostream iterator - copy (coll2.cbegin(), coll2.cend(), // source range - ostream_iterator(cout," ")); // destination range - cout << endl; + // process sum of elements + cout << "sum: " + << accumulate(coll.cbegin(), coll.cend(), // range + 0) // initial value + << endl; + // 45 - // copy elements of coll1 into coll2 in reverse order - // - now overwriting - copy (coll1.crbegin(), coll1.crend(), // source range - coll2.begin()); // destination range + // process sum of elements less 100 + cout << "sum: " + << accumulate(coll.cbegin(), coll.cend(), // range + -100) // initial value + << endl; + // -55 + // process product of elements + cout << "product: " + << accumulate(coll.cbegin(), coll.cend(), // range + 1, // initial value + multiplies()) // operation + << endl; + // 362880 - // print elements of coll2 again - copy (coll2.cbegin(), coll2.cend(), // source range - ostream_iterator(cout," ")); // destination range - cout << endl; + // process product of elements (use 0 as initial value) + cout << "product: " + << accumulate(coll.cbegin(), coll.cend(), // range + 0, // initial value + multiplies()) // operation + << endl; + // 0 } diff --git a/algo/accumulate1.cpp b/demo/algo/adjacentdiff1.cpp similarity index 32% rename from algo/accumulate1.cpp rename to demo/algo/adjacentdiff1.cpp index 4a6835ac01b5278a151b2bfb717f38bcaf2bf835..bbb6bbbdeb9cb55507b7eddf89a15e5940e7c147 100644 --- a/algo/accumulate1.cpp +++ b/demo/algo/adjacentdiff1.cpp @@ -11,36 +11,43 @@ #include "algostuff.hpp" using namespace std; -int main() -{ - vector coll; - - INSERT_ELEMENTS(coll, 1, 9); - PRINT_ELEMENTS(coll); - - // process sum of elements - cout << "sum: " - << accumulate(coll.cbegin(), coll.cend(), // range - 0) // initial value - << endl; - - // process sum of elements less 100 - cout << "sum: " - << accumulate(coll.cbegin(), coll.cend(), // range - -100) // initial value - << endl; - - // process product of elements - cout << "product: " - << accumulate(coll.cbegin(), coll.cend(), // range - 1, // initial value - multiplies()) // operation - << endl; - - // process product of elements (use 0 as initial value) - cout << "product: " - << accumulate(coll.cbegin(), coll.cend(), // range - 0, // initial value - multiplies()) // operation - << endl; +int main() { + deque coll; + + INSERT_ELEMENTS(coll, 1, 6); + PRINT_ELEMENTS(coll); + // 1 2 3 4 5 6 + + // print all differences between elements + // 1 1 1 1 1 1 + adjacent_difference(coll.cbegin(), coll.cend(), // source + ostream_iterator(cout, " ")); // destination + + cout << endl; + + // print all sums with the predecessors + // 1 3 5 7 9 11 + adjacent_difference(coll.cbegin(), coll.cend(), // source + ostream_iterator(cout, " "), // destination + plus()); // operation + + cout << endl; + + // print all products between elements + // 1 2 6 12 20 30 + adjacent_difference(coll.cbegin(), coll.cend(), // source + ostream_iterator(cout, " "), // destination + multiplies()); // operation + + cout << endl; + + std::vector col2 = {1, 2, 4, 7, 11, 16}; + std::vector result(col2.size()); + + std::adjacent_difference(col2.cbegin(), col2.cend(), result.begin()); + // 1 1 2 3 4 5 + for (const auto &val : result) { + std::cout << val << " "; + } + std::cout << std::endl; } diff --git a/algo/adjacentfind1.cpp b/demo/algo/adjacentfind1.cpp similarity index 38% rename from algo/adjacentfind1.cpp rename to demo/algo/adjacentfind1.cpp index 992e62514fd1b73baf62f58c2d64d7eab7d181e5..42e91a5df3afed082fa7d41e61a0d4ea68194ad6 100644 --- a/algo/adjacentfind1.cpp +++ b/demo/algo/adjacentfind1.cpp @@ -12,43 +12,39 @@ using namespace std; // return whether the second object has double the value of the first -bool doubled (int elem1, int elem2) -{ - return elem1 * 2 == elem2; -} - -int main() -{ - vector coll; - - coll.push_back(1); - coll.push_back(3); - coll.push_back(2); - coll.push_back(4); - coll.push_back(5); - coll.push_back(5); - coll.push_back(0); - - PRINT_ELEMENTS(coll,"coll: "); - - // search first two elements with equal value - vector::iterator pos; - pos = adjacent_find (coll.begin(), coll.end()); - - if (pos != coll.end()) { - cout << "first two elements with equal value have position " - << distance(coll.begin(),pos) + 1 - << endl; - } - - // search first two elements for which the second has double the value of the first - pos = adjacent_find (coll.begin(), coll.end(), // range - doubled); // criterion - - if (pos != coll.end()) { - cout << "first two elements with second value twice the " - << "first have pos. " - << distance(coll.begin(),pos) + 1 - << endl; - } +bool doubled(int elem1, int elem2) { return elem1 * 2 == elem2; } + +int main() { + vector coll; + + coll.push_back(1); + coll.push_back(3); + coll.push_back(2); + coll.push_back(4); + coll.push_back(5); + coll.push_back(5); + coll.push_back(0); + + // 1 3 2 4 5 5 0 + PRINT_ELEMENTS(coll, "coll: "); + + // search first two elements with equal value + vector::iterator pos; + pos = adjacent_find(coll.begin(), coll.end()); + // 5 + if (pos != coll.end()) { + cout << "first two elements with equal value have position " + << distance(coll.begin(), pos) + 1 << endl; + } + + // search first two elements for which the second has double the value of the + // first + pos = adjacent_find(coll.begin(), coll.end(), // range + doubled); // criterion + + // 3 + if (pos != coll.end()) { + cout << "first two elements with second value twice the " + << "first have pos. " << distance(coll.begin(), pos) + 1 << endl; + } } diff --git a/algo/algostuff.hpp b/demo/algo/algostuff.hpp similarity index 100% rename from algo/algostuff.hpp rename to demo/algo/algostuff.hpp diff --git a/algo/allanynone1.cpp b/demo/algo/allanynone1.cpp similarity index 45% rename from algo/allanynone1.cpp rename to demo/algo/allanynone1.cpp index 33dc15029c79f16c59b930e9669cdf305071186e..47e0c8c0effdac5a6b3a72900b3d3b7db0a9bb5d 100644 --- a/algo/allanynone1.cpp +++ b/demo/algo/allanynone1.cpp @@ -11,24 +11,27 @@ #include "algostuff.hpp" using namespace std; -int main() -{ - vector coll; - vector::iterator pos; +int main() { + vector coll; + vector::iterator pos; - INSERT_ELEMENTS(coll,1,9); - PRINT_ELEMENTS(coll,"coll: "); + INSERT_ELEMENTS(coll, 1, 9); - // define an object for the predicate (using a lambda) - auto isEven = [](int elem) { - return elem%2==0; - }; + // 1 2 3 4 5 6 7 8 9 + PRINT_ELEMENTS(coll, "coll: "); - // print whether all, any, or none of the elements are/is even - cout << boolalpha << "all even?: " - << all_of(coll.cbegin(),coll.cend(), isEven) << endl; - cout << "any even?: " - << any_of(coll.cbegin(),coll.cend(), isEven) << endl; - cout << "none even?: " - << none_of(coll.cbegin(),coll.cend(), isEven) << endl; + // define an object for the predicate (using a lambda) + auto isEven = [](int elem) { return elem % 2 == 0; }; + + // print whether all, any, or none of the elements are/is even + + // false + cout << boolalpha + << "all even?: " << all_of(coll.cbegin(), coll.cend(), isEven) << endl; + + // true + cout << "any even?: " << any_of(coll.cbegin(), coll.cend(), isEven) << endl; + + // false + cout << "none even?: " << none_of(coll.cbegin(), coll.cend(), isEven) << endl; } diff --git a/algo/binarysearch1.cpp b/demo/algo/binarysearch1.cpp similarity index 50% rename from algo/binarysearch1.cpp rename to demo/algo/binarysearch1.cpp index 93c611e7fa5ecd67c5c7e2a4591ad55f2167192e..dc0505ecebbf7427c16416b8c4e5dd239f57d378 100644 --- a/algo/binarysearch1.cpp +++ b/demo/algo/binarysearch1.cpp @@ -11,26 +11,26 @@ #include "algostuff.hpp" using namespace std; -int main() -{ - list coll; +int main() { + list coll; - INSERT_ELEMENTS(coll,1,9); - PRINT_ELEMENTS(coll); + INSERT_ELEMENTS(coll, 1, 9); + // 1 2 3 4 5 6 7 8 9 + PRINT_ELEMENTS(coll); - // check existence of element with value 5 - if (binary_search(coll.cbegin(), coll.cend(), 5)) { - cout << "5 is present" << endl; - } - else { - cout << "5 is not present" << endl; - } + // check existence of element with value 5 + // 5 is present + if (binary_search(coll.cbegin(), coll.cend(), 5)) { + cout << "5 is present" << endl; + } else { + cout << "5 is not present" << endl; + } - // check existence of element with value 42 - if (binary_search(coll.cbegin(), coll.cend(), 42)) { - cout << "42 is present" << endl; - } - else { - cout << "42 is not present" << endl; - } + // check existence of element with value 42 + // 42 is not present + if (binary_search(coll.cbegin(), coll.cend(), 42)) { + cout << "42 is present" << endl; + } else { + cout << "42 is not present" << endl; + } } diff --git a/algo/count1.cpp b/demo/algo/bounds1.cpp similarity index 36% rename from algo/count1.cpp rename to demo/algo/bounds1.cpp index 3d39b67329cdcc9839f4a87be1fed33130f5f7a3..fb33e3c7df2b29249abe975a687b31e0e2699656 100644 --- a/algo/count1.cpp +++ b/demo/algo/bounds1.cpp @@ -11,29 +11,30 @@ #include "algostuff.hpp" using namespace std; -int main() -{ - vector coll; - int num; - INSERT_ELEMENTS(coll,1,9); - PRINT_ELEMENTS(coll,"coll: "); +int main() { + list coll; - // count elements with value 4 - num = count (coll.cbegin(), coll.cend(), // range - 4); // value - cout << "number of elements equal to 4: " << num << endl; + INSERT_ELEMENTS(coll, 1, 9); + INSERT_ELEMENTS(coll, 1, 9); + coll.sort(); + // 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 + PRINT_ELEMENTS(coll); - // count elements with even value - num = count_if (coll.cbegin(), coll.cend(), // range - [](int elem){ // criterion - return elem%2==0; - }); - cout << "number of elements with even value: " << num << endl; + // print first and last position 5 could get inserted + auto pos1 = lower_bound(coll.cbegin(), coll.cend(), 5); + auto pos2 = upper_bound(coll.cbegin(), coll.cend(), 5); - // count elements that are greater than value 4 - num = count_if (coll.cbegin(), coll.cend(), // range - [](int elem){ // criterion - return elem>4; - }); - cout << "number of elements greater than 4: " << num << endl; + // 5 could get position 9 up to 11 without breaking the sorting + cout << "5 could get position " << distance(coll.cbegin(), pos1) + 1 + << " up to " << distance(coll.cbegin(), pos2) + 1 + << " without breaking the sorting" << endl; + + // insert 3 at the first possible position without breaking the sorting + coll.insert(lower_bound(coll.begin(), coll.end(), 3), 3); + + // insert 7 at the last possible position without breaking the sorting + coll.insert(upper_bound(coll.begin(), coll.end(), 7), 7); + + // 1 1 2 2 3 3 3 4 4 5 5 6 6 7 7 7 8 8 9 9 + PRINT_ELEMENTS(coll); } diff --git a/algo/bounds1.cpp b/demo/algo/copy1.cpp similarity index 35% rename from algo/bounds1.cpp rename to demo/algo/copy1.cpp index 724c1de0b8d03f93d78e202ee199030ada74003f..93ec9a2235a609c0c2a79b2dbdde3973dc463b74 100644 --- a/algo/bounds1.cpp +++ b/demo/algo/copy1.cpp @@ -11,36 +11,32 @@ #include "algostuff.hpp" using namespace std; -int main() -{ - list coll; +int main() { + vector coll1 = {"Hello", "this", "is", "an", "example"}; + list coll2; - INSERT_ELEMENTS(coll,1,9); - INSERT_ELEMENTS(coll,1,9); - coll.sort (); - PRINT_ELEMENTS(coll); + // copy elements of coll1 into coll2 + // - use back inserter to insert instead of overwrite + std::copy(coll1.cbegin(), coll1.cend(), // source range + std::back_inserter(coll2)); // destination range - // print first and last position 5 could get inserted - auto pos1 = lower_bound (coll.cbegin(), coll.cend(), - 5); - auto pos2 = upper_bound (coll.cbegin(), coll.cend(), - 5); + // print elements of coll2 + // - copy elements to cout using an ostream iterator + std::copy(coll2.cbegin(), coll2.cend(), // source range + ostream_iterator(cout, " ")); // destination range - cout << "5 could get position " - << distance(coll.cbegin(),pos1) + 1 - << " up to " - << distance(coll.cbegin(),pos2) + 1 - << " without breaking the sorting" << endl; + // Hello this is an example + cout << endl; - // insert 3 at the first possible position without breaking the sorting - coll.insert (lower_bound(coll.begin(),coll.end(), - 3), - 3); + // copy elements of coll1 into coll2 in reverse order + // - now overwriting + std::copy(coll1.crbegin(), coll1.crend(), // source range + coll2.begin()); // destination range - // insert 7 at the last possible position without breaking the sorting - coll.insert (upper_bound(coll.begin(),coll.end(), - 7), - 7); + // print elements of coll2 again + std::copy(coll2.cbegin(), coll2.cend(), // source range + ostream_iterator(cout, " ")); // destination range - PRINT_ELEMENTS(coll); + // example an is this Hello + cout << endl; } diff --git a/algo/copy2.cpp b/demo/algo/copy2.cpp similarity index 35% rename from algo/copy2.cpp rename to demo/algo/copy2.cpp index 626aa05b55fabf173843931ad7ba074471001c7d..7f32ab5703f92607dcb47825670772a78a67888d 100644 --- a/algo/copy2.cpp +++ b/demo/algo/copy2.cpp @@ -11,25 +11,30 @@ #include "algostuff.hpp" using namespace std; -int main() -{ - // initialize source collection with "..........abcdef.........." - vector source(10,'.'); - for (int c='a'; c<='f'; c++) { - source.push_back(c); - } - source.insert(source.end(),10,'.'); - PRINT_ELEMENTS(source,"source: "); +int main() { + // initialize source collection with "..........abcdef.........." + vector source(10, '.'); + for (int c = 'a'; c <= 'f'; c++) { + source.push_back(c); + } + source.insert(source.end(), 10, '.'); + // . . . . . . . . . . a b c d e f . . . . . . . . . . + PRINT_ELEMENTS(source, "source: "); - // copy all letters three elements in front of the 'a' - vector c1(source.cbegin(),source.cend()); - copy (c1.cbegin()+10, c1.cbegin()+16, // source range - c1.begin()+7); // destination range - PRINT_ELEMENTS(c1,"c1: "); + // copy all letters three elements in front of the 'a' + vector c1(source.cbegin(), source.cend()); + // a b c d e f + std::copy(c1.cbegin() + 10, c1.cbegin() + 16, // source range + c1.begin() + 7); // destination range - // copy all letters three elements behind the 'f' - vector c2(source.cbegin(),source.cend()); - copy_backward (c2.cbegin()+10, c2.cbegin()+16, // source range - c2.begin()+19); // destination range - PRINT_ELEMENTS(c2,"c2: "); + // . . . . . . . a b c d e f d e f . . . . . . . . . . + PRINT_ELEMENTS(c1, "c1: "); + + // copy all letters three elements behind the 'f' + vector c2(source.cbegin(), source.cend()); + // a b c d e f + copy_backward(c2.cbegin() + 10, c2.cbegin() + 16, // source range + c2.begin() + 19); // destination range + // . . . . . . . . . . a b c a b c d e f . . . . . . . + PRINT_ELEMENTS(c2, "c2: "); } diff --git a/algo/copy3.cpp b/demo/algo/copy3.cpp similarity index 100% rename from algo/copy3.cpp rename to demo/algo/copy3.cpp diff --git a/algo/adjacentdiff1.cpp b/demo/algo/count1.cpp similarity index 37% rename from algo/adjacentdiff1.cpp rename to demo/algo/count1.cpp index 761aa252a083dc060350c02949a2afbe4cfc3f20..479be087239163f034f767a3969e5e35c1986571 100644 --- a/algo/adjacentdiff1.cpp +++ b/demo/algo/count1.cpp @@ -11,27 +11,32 @@ #include "algostuff.hpp" using namespace std; -int main() -{ - deque coll; +int main() { + vector coll; + int num; + INSERT_ELEMENTS(coll, 1, 9); + // 1 2 3 4 5 6 7 8 9 + PRINT_ELEMENTS(coll, "coll: "); - INSERT_ELEMENTS(coll, 1, 6); - PRINT_ELEMENTS(coll); + // count elements with value 4 + // 1 + num = count(coll.cbegin(), coll.cend(), // range + 4); // value + cout << "number of elements equal to 4: " << num << endl; - // print all differences between elements - adjacent_difference(coll.cbegin(), coll.cend(), // source - ostream_iterator(cout, " ")); // destination - cout << endl; + // count elements with even value + // 4 + num = count_if(coll.cbegin(), coll.cend(), // range + [](int elem) { // criterion + return elem % 2 == 0; + }); + cout << "number of elements with even value: " << num << endl; - // print all sums with the predecessors - adjacent_difference(coll.cbegin(), coll.cend(), // source - ostream_iterator(cout, " "), // destination - plus()); // operation - cout << endl; - - // print all products between elements - adjacent_difference(coll.cbegin(), coll.cend(), // source - ostream_iterator(cout, " "), // destination - multiplies()); // operation - cout << endl; + // count elements that are greater than value 4 + // 5 + num = count_if(coll.cbegin(), coll.cend(), // range + [](int elem) { // criterion + return elem > 4; + }); + cout << "number of elements greater than 4: " << num << endl; } diff --git a/algo/equal1.cpp b/demo/algo/equal1.cpp similarity index 35% rename from algo/equal1.cpp rename to demo/algo/equal1.cpp index e96fcc8d88be08d36f99e4df51e3648d0c01c401..35eee76f7691e6825edd304df5325aeacf7faa69 100644 --- a/algo/equal1.cpp +++ b/demo/algo/equal1.cpp @@ -11,38 +11,35 @@ #include "algostuff.hpp" using namespace std; -bool bothEvenOrOdd (int elem1, int elem2) -{ - return elem1 % 2 == elem2 % 2; -} - -int main() -{ - vector coll1; - list coll2; +bool bothEvenOrOdd(int elem1, int elem2) { return elem1 % 2 == elem2 % 2; } - INSERT_ELEMENTS(coll1,1,7); - INSERT_ELEMENTS(coll2,3,9); +int main() { + vector coll1; + list coll2; - PRINT_ELEMENTS(coll1,"coll1: "); - PRINT_ELEMENTS(coll2,"coll2: "); + INSERT_ELEMENTS(coll1, 1, 7); + INSERT_ELEMENTS(coll2, 3, 9); + // 1 2 3 4 5 6 7 + PRINT_ELEMENTS(coll1, "coll1: "); + // 3 4 5 6 7 8 9 + PRINT_ELEMENTS(coll2, "coll2: "); - // check whether both collections are equal - if (equal (coll1.begin(), coll1.end(), // first range - coll2.begin())) { // second range - cout << "coll1 == coll2" << endl; - } - else { - cout << "coll1 != coll2" << endl; - } + // check whether both collections are equal + // coll1 != coll2 + if (equal(coll1.begin(), coll1.end(), // first range + coll2.begin())) { // second range + cout << "coll1 == coll2" << endl; + } else { + cout << "coll1 != coll2" << endl; + } - // check for corresponding even and odd elements - if (equal (coll1.begin(), coll1.end(), // first range - coll2.begin(), // second range - bothEvenOrOdd)) { // comparison criterion - cout << "even and odd elements correspond" << endl; - } - else { - cout << "even and odd elements do not correspond" << endl; - } + // check for corresponding even and odd elements + // even and odd elements correspond 同奇同偶 + if (equal(coll1.begin(), coll1.end(), // first range + coll2.begin(), // second range + bothEvenOrOdd)) { // comparison criterion + cout << "even and odd elements correspond" << endl; + } else { + cout << "even and odd elements do not correspond" << endl; + } } diff --git a/algo/equalrange1.cpp b/demo/algo/equalrange1.cpp similarity index 47% rename from algo/equalrange1.cpp rename to demo/algo/equalrange1.cpp index daeb400462d816763fe866302d02712360a63524..5c9aac792c77da6ee4c36cfeea22fdf1e600f1ad 100644 --- a/algo/equalrange1.cpp +++ b/demo/algo/equalrange1.cpp @@ -11,23 +11,22 @@ #include "algostuff.hpp" using namespace std; -int main() -{ - list coll; +int main() { + list coll; - INSERT_ELEMENTS(coll,1,9); - INSERT_ELEMENTS(coll,1,9); - coll.sort (); - PRINT_ELEMENTS(coll); + INSERT_ELEMENTS(coll, 1, 9); + INSERT_ELEMENTS(coll, 1, 9); + coll.sort(); - // print first and last position 5 could get inserted - pair::const_iterator,list::const_iterator> range; - range = equal_range (coll.cbegin(), coll.cend(), - 5); + // 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 + PRINT_ELEMENTS(coll); - cout << "5 could get position " - << distance(coll.cbegin(),range.first) + 1 - << " up to " - << distance(coll.cbegin(),range.second) + 1 - << " without breaking the sorting" << endl; + // print first and last position 5 could get inserted + pair::const_iterator, list::const_iterator> range; + range = equal_range(coll.cbegin(), coll.cend(), 5); + + // 5 could get position 9 up to 11 without breaking the sorting + cout << "5 could get position " << distance(coll.cbegin(), range.first) + 1 + << " up to " << distance(coll.cbegin(), range.second) + 1 + << " without breaking the sorting" << endl; } diff --git a/demo/algo/fill1.cpp b/demo/algo/fill1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5efdcf908fd308d755c8d084e5ebd9c145f87a60 --- /dev/null +++ b/demo/algo/fill1.cpp @@ -0,0 +1,52 @@ +/* The following code example is taken from the book + * "The C++ Standard Library - A Tutorial and Reference, 2nd Edition" + * by Nicolai M. Josuttis, Addison-Wesley, 2012 + * + * (C) Copyright Nicolai M. Josuttis 2012. + * Permission to copy, use, modify, sell and distribute this software + * is granted provided this copyright notice appears in all copies. + * This software is provided "as is" without express or implied + * warranty, and with no claim as to its suitability for any purpose. + */ +#include "algostuff.hpp" +using namespace std; + +int main() { + // print ten times 7.7 + fill_n(ostream_iterator(cout, " "), // beginning of destination + 10, // count + 7.7); // new value + cout << endl; + + list coll; + + // insert "hello" nine times + fill_n(back_inserter(coll), // beginning of destination + 9, // count + "hello"); // new value + + // hello hello hello hello hello hello hello hello hello + PRINT_ELEMENTS(coll, "coll: "); + + // overwrite all elements with "again" + // again again again again again again again again again + fill(coll.begin(), coll.end(), // destination + "again"); // new value + PRINT_ELEMENTS(coll, "coll: "); + + // replace all but two elements with "hi" + fill_n(coll.begin(), // beginning of destination + coll.size() - 2, // count + "hi"); // new value + + // hi hi hi hi hi hi hi again again + PRINT_ELEMENTS(coll, "coll: "); + + // replace the second and up to the last element but one with "hmmm" + list::iterator pos1, pos2; + pos1 = coll.begin(); + pos2 = coll.end(); + fill(++pos1, --pos2, // destination + "hmmm"); // new value + PRINT_ELEMENTS(coll, "coll: "); +} diff --git a/algo/find1.cpp b/demo/algo/find1.cpp similarity index 100% rename from algo/find1.cpp rename to demo/algo/find1.cpp diff --git a/algo/find2.cpp b/demo/algo/find2.cpp similarity index 100% rename from algo/find2.cpp rename to demo/algo/find2.cpp diff --git a/algo/findend1.cpp b/demo/algo/findend1.cpp similarity index 100% rename from algo/findend1.cpp rename to demo/algo/findend1.cpp diff --git a/algo/findof1.cpp b/demo/algo/findof1.cpp similarity index 100% rename from algo/findof1.cpp rename to demo/algo/findof1.cpp diff --git a/algo/foreach1.cpp b/demo/algo/foreach1.cpp similarity index 100% rename from algo/foreach1.cpp rename to demo/algo/foreach1.cpp diff --git a/algo/foreach2.cpp b/demo/algo/foreach2.cpp similarity index 100% rename from algo/foreach2.cpp rename to demo/algo/foreach2.cpp diff --git a/algo/foreach3.cpp b/demo/algo/foreach3.cpp similarity index 100% rename from algo/foreach3.cpp rename to demo/algo/foreach3.cpp diff --git a/algo/generate1.cpp b/demo/algo/generate1.cpp similarity index 100% rename from algo/generate1.cpp rename to demo/algo/generate1.cpp diff --git a/algo/heap1.cpp b/demo/algo/heap1.cpp similarity index 100% rename from algo/heap1.cpp rename to demo/algo/heap1.cpp diff --git a/algo/includes1.cpp b/demo/algo/includes1.cpp similarity index 100% rename from algo/includes1.cpp rename to demo/algo/includes1.cpp diff --git a/algo/innerproduct1.cpp b/demo/algo/innerproduct1.cpp similarity index 100% rename from algo/innerproduct1.cpp rename to demo/algo/innerproduct1.cpp diff --git a/algo/inplacemerge1.cpp b/demo/algo/inplacemerge1.cpp similarity index 100% rename from algo/inplacemerge1.cpp rename to demo/algo/inplacemerge1.cpp diff --git a/algo/iota1.cpp b/demo/algo/iota1.cpp similarity index 100% rename from algo/iota1.cpp rename to demo/algo/iota1.cpp diff --git a/algo/isheap1.cpp b/demo/algo/isheap1.cpp similarity index 100% rename from algo/isheap1.cpp rename to demo/algo/isheap1.cpp diff --git a/algo/ispartitioned1.cpp b/demo/algo/ispartitioned1.cpp similarity index 100% rename from algo/ispartitioned1.cpp rename to demo/algo/ispartitioned1.cpp diff --git a/algo/ispermutation1.cpp b/demo/algo/ispermutation1.cpp similarity index 100% rename from algo/ispermutation1.cpp rename to demo/algo/ispermutation1.cpp diff --git a/algo/issorted1.cpp b/demo/algo/issorted1.cpp similarity index 100% rename from algo/issorted1.cpp rename to demo/algo/issorted1.cpp diff --git a/algo/lexicocmp1.cpp b/demo/algo/lexicocmp1.cpp similarity index 100% rename from algo/lexicocmp1.cpp rename to demo/algo/lexicocmp1.cpp diff --git a/algo/merge1.cpp b/demo/algo/merge1.cpp similarity index 100% rename from algo/merge1.cpp rename to demo/algo/merge1.cpp diff --git a/algo/minmax1.cpp b/demo/algo/minmax1.cpp similarity index 100% rename from algo/minmax1.cpp rename to demo/algo/minmax1.cpp diff --git a/algo/mismatch1.cpp b/demo/algo/mismatch1.cpp similarity index 100% rename from algo/mismatch1.cpp rename to demo/algo/mismatch1.cpp diff --git a/algo/move1.cpp b/demo/algo/move1.cpp similarity index 100% rename from algo/move1.cpp rename to demo/algo/move1.cpp diff --git a/algo/nthelement1.cpp b/demo/algo/nthelement1.cpp similarity index 100% rename from algo/nthelement1.cpp rename to demo/algo/nthelement1.cpp diff --git a/algo/partialsort1.cpp b/demo/algo/partialsort1.cpp similarity index 100% rename from algo/partialsort1.cpp rename to demo/algo/partialsort1.cpp diff --git a/algo/partialsort2.cpp b/demo/algo/partialsort2.cpp similarity index 100% rename from algo/partialsort2.cpp rename to demo/algo/partialsort2.cpp diff --git a/algo/partialsum1.cpp b/demo/algo/partialsum1.cpp similarity index 100% rename from algo/partialsum1.cpp rename to demo/algo/partialsum1.cpp diff --git a/algo/partition1.cpp b/demo/algo/partition1.cpp similarity index 100% rename from algo/partition1.cpp rename to demo/algo/partition1.cpp diff --git a/algo/partitioncopy1.cpp b/demo/algo/partitioncopy1.cpp similarity index 100% rename from algo/partitioncopy1.cpp rename to demo/algo/partitioncopy1.cpp diff --git a/algo/permutation1.cpp b/demo/algo/permutation1.cpp similarity index 100% rename from algo/permutation1.cpp rename to demo/algo/permutation1.cpp diff --git a/algo/randomshuffle1.cpp b/demo/algo/randomshuffle1.cpp similarity index 100% rename from algo/randomshuffle1.cpp rename to demo/algo/randomshuffle1.cpp diff --git a/algo/relabs1.cpp b/demo/algo/relabs1.cpp similarity index 100% rename from algo/relabs1.cpp rename to demo/algo/relabs1.cpp diff --git a/algo/remove1.cpp b/demo/algo/remove1.cpp similarity index 100% rename from algo/remove1.cpp rename to demo/algo/remove1.cpp diff --git a/algo/remove2.cpp b/demo/algo/remove2.cpp similarity index 100% rename from algo/remove2.cpp rename to demo/algo/remove2.cpp diff --git a/algo/replace1.cpp b/demo/algo/replace1.cpp similarity index 100% rename from algo/replace1.cpp rename to demo/algo/replace1.cpp diff --git a/algo/replace2.cpp b/demo/algo/replace2.cpp similarity index 100% rename from algo/replace2.cpp rename to demo/algo/replace2.cpp diff --git a/algo/reverse1.cpp b/demo/algo/reverse1.cpp similarity index 100% rename from algo/reverse1.cpp rename to demo/algo/reverse1.cpp diff --git a/algo/rotate1.cpp b/demo/algo/rotate1.cpp similarity index 100% rename from algo/rotate1.cpp rename to demo/algo/rotate1.cpp diff --git a/algo/rotate2.cpp b/demo/algo/rotate2.cpp similarity index 100% rename from algo/rotate2.cpp rename to demo/algo/rotate2.cpp diff --git a/algo/search1.cpp b/demo/algo/search1.cpp similarity index 100% rename from algo/search1.cpp rename to demo/algo/search1.cpp diff --git a/algo/search2.cpp b/demo/algo/search2.cpp similarity index 100% rename from algo/search2.cpp rename to demo/algo/search2.cpp diff --git a/algo/searchn1.cpp b/demo/algo/searchn1.cpp similarity index 100% rename from algo/searchn1.cpp rename to demo/algo/searchn1.cpp diff --git a/algo/shuffle1.cpp b/demo/algo/shuffle1.cpp similarity index 100% rename from algo/shuffle1.cpp rename to demo/algo/shuffle1.cpp diff --git a/algo/sort1.cpp b/demo/algo/sort1.cpp similarity index 100% rename from algo/sort1.cpp rename to demo/algo/sort1.cpp diff --git a/algo/sort2.cpp b/demo/algo/sort2.cpp similarity index 100% rename from algo/sort2.cpp rename to demo/algo/sort2.cpp diff --git a/algo/sorted1.cpp b/demo/algo/sorted1.cpp similarity index 100% rename from algo/sorted1.cpp rename to demo/algo/sorted1.cpp diff --git a/algo/swapranges1.cpp b/demo/algo/swapranges1.cpp similarity index 100% rename from algo/swapranges1.cpp rename to demo/algo/swapranges1.cpp diff --git a/algo/transform1.cpp b/demo/algo/transform1.cpp similarity index 100% rename from algo/transform1.cpp rename to demo/algo/transform1.cpp diff --git a/algo/transform2.cpp b/demo/algo/transform2.cpp similarity index 100% rename from algo/transform2.cpp rename to demo/algo/transform2.cpp diff --git a/algo/unique1.cpp b/demo/algo/unique1.cpp similarity index 100% rename from algo/unique1.cpp rename to demo/algo/unique1.cpp diff --git a/algo/unique2.cpp b/demo/algo/unique2.cpp similarity index 100% rename from algo/unique2.cpp rename to demo/algo/unique2.cpp diff --git a/algo/unique3.cpp b/demo/algo/unique3.cpp similarity index 100% rename from algo/unique3.cpp rename to demo/algo/unique3.cpp diff --git a/alloc/myalloc03.cpp b/demo/alloc/myalloc03.cpp similarity index 100% rename from alloc/myalloc03.cpp rename to demo/alloc/myalloc03.cpp diff --git a/alloc/myalloc03.hpp b/demo/alloc/myalloc03.hpp similarity index 100% rename from alloc/myalloc03.hpp rename to demo/alloc/myalloc03.hpp diff --git a/alloc/myalloc11.cpp b/demo/alloc/myalloc11.cpp similarity index 100% rename from alloc/myalloc11.cpp rename to demo/alloc/myalloc11.cpp diff --git a/alloc/myalloc11.hpp b/demo/alloc/myalloc11.hpp similarity index 100% rename from alloc/myalloc11.hpp rename to demo/alloc/myalloc11.hpp diff --git a/concurrency/async1.cpp b/demo/concurrency/async1.cpp similarity index 100% rename from concurrency/async1.cpp rename to demo/concurrency/async1.cpp diff --git a/concurrency/async2.cpp b/demo/concurrency/async2.cpp similarity index 100% rename from concurrency/async2.cpp rename to demo/concurrency/async2.cpp diff --git a/concurrency/async3.cpp b/demo/concurrency/async3.cpp similarity index 100% rename from concurrency/async3.cpp rename to demo/concurrency/async3.cpp diff --git a/concurrency/atomics1.cpp b/demo/concurrency/atomics1.cpp similarity index 100% rename from concurrency/atomics1.cpp rename to demo/concurrency/atomics1.cpp diff --git a/concurrency/condvar1.cpp b/demo/concurrency/condvar1.cpp similarity index 100% rename from concurrency/condvar1.cpp rename to demo/concurrency/condvar1.cpp diff --git a/concurrency/condvar2.cpp b/demo/concurrency/condvar2.cpp similarity index 100% rename from concurrency/condvar2.cpp rename to demo/concurrency/condvar2.cpp diff --git a/concurrency/mutex1.cpp b/demo/concurrency/mutex1.cpp similarity index 100% rename from concurrency/mutex1.cpp rename to demo/concurrency/mutex1.cpp diff --git a/concurrency/promise1.cpp b/demo/concurrency/promise1.cpp similarity index 100% rename from concurrency/promise1.cpp rename to demo/concurrency/promise1.cpp diff --git a/concurrency/sharedfuture1.cpp b/demo/concurrency/sharedfuture1.cpp similarity index 100% rename from concurrency/sharedfuture1.cpp rename to demo/concurrency/sharedfuture1.cpp diff --git a/concurrency/thread1.cpp b/demo/concurrency/thread1.cpp similarity index 100% rename from concurrency/thread1.cpp rename to demo/concurrency/thread1.cpp diff --git a/cont/array1.cpp b/demo/cont/array1.cpp similarity index 100% rename from cont/array1.cpp rename to demo/cont/array1.cpp diff --git a/cont/buckets.hpp b/demo/cont/buckets.hpp similarity index 100% rename from cont/buckets.hpp rename to demo/cont/buckets.hpp diff --git a/cont/cstylearray1.cpp b/demo/cont/cstylearray1.cpp similarity index 100% rename from cont/cstylearray1.cpp rename to demo/cont/cstylearray1.cpp diff --git a/cont/cstylearray1old.cpp b/demo/cont/cstylearray1old.cpp similarity index 100% rename from cont/cstylearray1old.cpp rename to demo/cont/cstylearray1old.cpp diff --git a/cont/deque1.cpp b/demo/cont/deque1.cpp similarity index 100% rename from cont/deque1.cpp rename to demo/cont/deque1.cpp diff --git a/cont/findbefore.hpp b/demo/cont/findbefore.hpp similarity index 100% rename from cont/findbefore.hpp rename to demo/cont/findbefore.hpp diff --git a/cont/forwardlist1.cpp b/demo/cont/forwardlist1.cpp similarity index 100% rename from cont/forwardlist1.cpp rename to demo/cont/forwardlist1.cpp diff --git a/cont/forwardlistfind1.cpp b/demo/cont/forwardlistfind1.cpp similarity index 100% rename from cont/forwardlistfind1.cpp rename to demo/cont/forwardlistfind1.cpp diff --git a/cont/forwardlistsplice1.cpp b/demo/cont/forwardlistsplice1.cpp similarity index 100% rename from cont/forwardlistsplice1.cpp rename to demo/cont/forwardlistsplice1.cpp diff --git a/cont/hashfunc1.cpp b/demo/cont/hashfunc1.cpp similarity index 100% rename from cont/hashfunc1.cpp rename to demo/cont/hashfunc1.cpp diff --git a/cont/hashfunc2.cpp b/demo/cont/hashfunc2.cpp similarity index 100% rename from cont/hashfunc2.cpp rename to demo/cont/hashfunc2.cpp diff --git a/cont/hashval.hpp b/demo/cont/hashval.hpp similarity index 100% rename from cont/hashval.hpp rename to demo/cont/hashval.hpp diff --git a/cont/list1.cpp b/demo/cont/list1.cpp similarity index 100% rename from cont/list1.cpp rename to demo/cont/list1.cpp diff --git a/cont/map1.cpp b/demo/cont/map1.cpp similarity index 100% rename from cont/map1.cpp rename to demo/cont/map1.cpp diff --git a/cont/map2.cpp b/demo/cont/map2.cpp similarity index 100% rename from cont/map2.cpp rename to demo/cont/map2.cpp diff --git a/cont/mapcmp1.cpp b/demo/cont/mapcmp1.cpp similarity index 100% rename from cont/mapcmp1.cpp rename to demo/cont/mapcmp1.cpp diff --git a/cont/mapfind1.cpp b/demo/cont/mapfind1.cpp similarity index 100% rename from cont/mapfind1.cpp rename to demo/cont/mapfind1.cpp diff --git a/cont/multimap1.cpp b/demo/cont/multimap1.cpp similarity index 100% rename from cont/multimap1.cpp rename to demo/cont/multimap1.cpp diff --git a/cont/multiset1.cpp b/demo/cont/multiset1.cpp similarity index 100% rename from cont/multiset1.cpp rename to demo/cont/multiset1.cpp diff --git a/cont/newkey.hpp b/demo/cont/newkey.hpp similarity index 100% rename from cont/newkey.hpp rename to demo/cont/newkey.hpp diff --git a/cont/print.hpp b/demo/cont/print.hpp similarity index 100% rename from cont/print.hpp rename to demo/cont/print.hpp diff --git a/cont/refsem1.cpp b/demo/cont/refsem1.cpp similarity index 100% rename from cont/refsem1.cpp rename to demo/cont/refsem1.cpp diff --git a/cont/refwrap1.cpp b/demo/cont/refwrap1.cpp similarity index 100% rename from cont/refwrap1.cpp rename to demo/cont/refwrap1.cpp diff --git a/cont/set1.cpp b/demo/cont/set1.cpp similarity index 100% rename from cont/set1.cpp rename to demo/cont/set1.cpp diff --git a/cont/setcmp1.cpp b/demo/cont/setcmp1.cpp similarity index 100% rename from cont/setcmp1.cpp rename to demo/cont/setcmp1.cpp diff --git a/cont/setrange1.cpp b/demo/cont/setrange1.cpp similarity index 100% rename from cont/setrange1.cpp rename to demo/cont/setrange1.cpp diff --git a/cont/sortset.cpp b/demo/cont/sortset.cpp similarity index 100% rename from cont/sortset.cpp rename to demo/cont/sortset.cpp diff --git a/cont/sortvec.cpp b/demo/cont/sortvec.cpp similarity index 100% rename from cont/sortvec.cpp rename to demo/cont/sortvec.cpp diff --git a/cont/unordinspect1.cpp b/demo/cont/unordinspect1.cpp similarity index 100% rename from cont/unordinspect1.cpp rename to demo/cont/unordinspect1.cpp diff --git a/cont/unordmultimap1.cpp b/demo/cont/unordmultimap1.cpp similarity index 100% rename from cont/unordmultimap1.cpp rename to demo/cont/unordmultimap1.cpp diff --git a/cont/unordmultiset1.cpp b/demo/cont/unordmultiset1.cpp similarity index 100% rename from cont/unordmultiset1.cpp rename to demo/cont/unordmultiset1.cpp diff --git a/cont/unordset1.cpp b/demo/cont/unordset1.cpp similarity index 100% rename from cont/unordset1.cpp rename to demo/cont/unordset1.cpp diff --git a/cont/vector1.cpp b/demo/cont/vector1.cpp similarity index 100% rename from cont/vector1.cpp rename to demo/cont/vector1.cpp diff --git a/contadapt/Queue.hpp b/demo/contadapt/Queue.hpp similarity index 100% rename from contadapt/Queue.hpp rename to demo/contadapt/Queue.hpp diff --git a/contadapt/Stack.hpp b/demo/contadapt/Stack.hpp similarity index 100% rename from contadapt/Stack.hpp rename to demo/contadapt/Stack.hpp diff --git a/contadapt/bitset1.cpp b/demo/contadapt/bitset1.cpp similarity index 100% rename from contadapt/bitset1.cpp rename to demo/contadapt/bitset1.cpp diff --git a/contadapt/bitset2.cpp b/demo/contadapt/bitset2.cpp similarity index 100% rename from contadapt/bitset2.cpp rename to demo/contadapt/bitset2.cpp diff --git a/contadapt/priorityqueue1.cpp b/demo/contadapt/priorityqueue1.cpp similarity index 100% rename from contadapt/priorityqueue1.cpp rename to demo/contadapt/priorityqueue1.cpp diff --git a/contadapt/queue1.cpp b/demo/contadapt/queue1.cpp similarity index 100% rename from contadapt/queue1.cpp rename to demo/contadapt/queue1.cpp diff --git a/contadapt/queue2.cpp b/demo/contadapt/queue2.cpp similarity index 100% rename from contadapt/queue2.cpp rename to demo/contadapt/queue2.cpp diff --git a/contadapt/stack1.cpp b/demo/contadapt/stack1.cpp similarity index 100% rename from contadapt/stack1.cpp rename to demo/contadapt/stack1.cpp diff --git a/contadapt/stack2.cpp b/demo/contadapt/stack2.cpp similarity index 100% rename from contadapt/stack2.cpp rename to demo/contadapt/stack2.cpp diff --git a/fo/bind1.cpp b/demo/fo/bind1.cpp similarity index 100% rename from fo/bind1.cpp rename to demo/fo/bind1.cpp diff --git a/fo/bind2.cpp b/demo/fo/bind2.cpp similarity index 100% rename from fo/bind2.cpp rename to demo/fo/bind2.cpp diff --git a/fo/compose3.cpp b/demo/fo/compose3.cpp similarity index 100% rename from fo/compose3.cpp rename to demo/fo/compose3.cpp diff --git a/fo/fopow.hpp b/demo/fo/fopow.hpp similarity index 100% rename from fo/fopow.hpp rename to demo/fo/fopow.hpp diff --git a/fo/fopow1.cpp b/demo/fo/fopow1.cpp similarity index 100% rename from fo/fopow1.cpp rename to demo/fo/fopow1.cpp diff --git a/fo/foreach3.cpp b/demo/fo/foreach3.cpp similarity index 100% rename from fo/foreach3.cpp rename to demo/fo/foreach3.cpp diff --git a/fo/lambda2.cpp b/demo/fo/lambda2.cpp similarity index 100% rename from fo/lambda2.cpp rename to demo/fo/lambda2.cpp diff --git a/fo/lambda3.cpp b/demo/fo/lambda3.cpp similarity index 100% rename from fo/lambda3.cpp rename to demo/fo/lambda3.cpp diff --git a/fo/lambda4.cpp b/demo/fo/lambda4.cpp similarity index 100% rename from fo/lambda4.cpp rename to demo/fo/lambda4.cpp diff --git a/fo/lambda5.cpp b/demo/fo/lambda5.cpp similarity index 100% rename from fo/lambda5.cpp rename to demo/fo/lambda5.cpp diff --git a/fo/lambda6.cpp b/demo/fo/lambda6.cpp similarity index 100% rename from fo/lambda6.cpp rename to demo/fo/lambda6.cpp diff --git a/fo/print.hpp b/demo/fo/print.hpp similarity index 100% rename from fo/print.hpp rename to demo/fo/print.hpp diff --git a/fo/removeif1.cpp b/demo/fo/removeif1.cpp similarity index 100% rename from fo/removeif1.cpp rename to demo/fo/removeif1.cpp diff --git a/fo/sequence1.cpp b/demo/fo/sequence1.cpp similarity index 100% rename from fo/sequence1.cpp rename to demo/fo/sequence1.cpp diff --git a/fo/sequence2.cpp b/demo/fo/sequence2.cpp similarity index 100% rename from fo/sequence2.cpp rename to demo/fo/sequence2.cpp diff --git a/fo/sort1.cpp b/demo/fo/sort1.cpp similarity index 100% rename from fo/sort1.cpp rename to demo/fo/sort1.cpp diff --git a/i18n/germanbool.cpp b/demo/i18n/germanbool.cpp similarity index 100% rename from i18n/germanbool.cpp rename to demo/i18n/germanbool.cpp diff --git a/i18n/loc1.cpp b/demo/i18n/loc1.cpp similarity index 100% rename from i18n/loc1.cpp rename to demo/i18n/loc1.cpp diff --git a/i18n/loc2.cpp b/demo/i18n/loc2.cpp similarity index 100% rename from i18n/loc2.cpp rename to demo/i18n/loc2.cpp diff --git a/i18n/moneymanipulator.cpp b/demo/i18n/moneymanipulator.cpp similarity index 100% rename from i18n/moneymanipulator.cpp rename to demo/i18n/moneymanipulator.cpp diff --git a/i18n/moneypunct.cpp b/demo/i18n/moneypunct.cpp similarity index 100% rename from i18n/moneypunct.cpp rename to demo/i18n/moneypunct.cpp diff --git a/i18n/numget.cpp b/demo/i18n/numget.cpp similarity index 100% rename from i18n/numget.cpp rename to demo/i18n/numget.cpp diff --git a/i18n/numput.cpp b/demo/i18n/numput.cpp similarity index 100% rename from i18n/numput.cpp rename to demo/i18n/numput.cpp diff --git a/i18n/timeget.cpp b/demo/i18n/timeget.cpp similarity index 100% rename from i18n/timeget.cpp rename to demo/i18n/timeget.cpp diff --git a/i18n/timeput.cpp b/demo/i18n/timeput.cpp similarity index 100% rename from i18n/timeput.cpp rename to demo/i18n/timeput.cpp diff --git a/i18n/wbuffer.cpp b/demo/i18n/wbuffer.cpp similarity index 100% rename from i18n/wbuffer.cpp rename to demo/i18n/wbuffer.cpp diff --git a/i18n/wstring2string.cpp b/demo/i18n/wstring2string.cpp similarity index 100% rename from i18n/wstring2string.cpp rename to demo/i18n/wstring2string.cpp diff --git a/i18n/wstring2string.hpp b/demo/i18n/wstring2string.hpp similarity index 100% rename from i18n/wstring2string.hpp rename to demo/i18n/wstring2string.hpp diff --git a/i18n/wstring2utf8.cpp b/demo/i18n/wstring2utf8.cpp similarity index 100% rename from i18n/wstring2utf8.cpp rename to demo/i18n/wstring2utf8.cpp diff --git a/i18n/wstring2utf8.hpp b/demo/i18n/wstring2utf8.hpp similarity index 100% rename from i18n/wstring2utf8.hpp rename to demo/i18n/wstring2utf8.hpp diff --git a/io/1-io.txt b/demo/io/1-io.txt similarity index 100% rename from io/1-io.txt rename to demo/io/1-io.txt diff --git a/io/2-io.txt b/demo/io/2-io.txt similarity index 100% rename from io/2-io.txt rename to demo/io/2-io.txt diff --git a/io/cat1.cpp b/demo/io/cat1.cpp similarity index 100% rename from io/cat1.cpp rename to demo/io/cat1.cpp diff --git a/io/cat2.cpp b/demo/io/cat2.cpp similarity index 100% rename from io/cat2.cpp rename to demo/io/cat2.cpp diff --git a/io/charcat1.cpp b/demo/io/charcat1.cpp similarity index 100% rename from io/charcat1.cpp rename to demo/io/charcat1.cpp diff --git a/io/charcat2.cpp b/demo/io/charcat2.cpp similarity index 100% rename from io/charcat2.cpp rename to demo/io/charcat2.cpp diff --git a/io/copy1.cpp b/demo/io/copy1.cpp similarity index 100% rename from io/copy1.cpp rename to demo/io/copy1.cpp diff --git a/io/copy2.cpp b/demo/io/copy2.cpp similarity index 100% rename from io/copy2.cpp rename to demo/io/copy2.cpp diff --git a/io/countlines1.cpp b/demo/io/countlines1.cpp similarity index 100% rename from io/countlines1.cpp rename to demo/io/countlines1.cpp diff --git a/io/example.dat b/demo/io/example.dat similarity index 100% rename from io/example.dat rename to demo/io/example.dat diff --git a/io/frac1in.hpp b/demo/io/frac1in.hpp similarity index 100% rename from io/frac1in.hpp rename to demo/io/frac1in.hpp diff --git a/io/frac1out.hpp b/demo/io/frac1out.hpp similarity index 100% rename from io/frac1out.hpp rename to demo/io/frac1out.hpp diff --git a/io/frac2in.hpp b/demo/io/frac2in.hpp similarity index 100% rename from io/frac2in.hpp rename to demo/io/frac2in.hpp diff --git a/io/frac2out.hpp b/demo/io/frac2out.hpp similarity index 100% rename from io/frac2out.hpp rename to demo/io/frac2out.hpp diff --git a/io/fstream1.cpp b/demo/io/fstream1.cpp similarity index 100% rename from io/fstream1.cpp rename to demo/io/fstream1.cpp diff --git a/io/fstream2.cpp b/demo/io/fstream2.cpp similarity index 100% rename from io/fstream2.cpp rename to demo/io/fstream2.cpp diff --git a/io/fstream2.tmp b/demo/io/fstream2.tmp similarity index 100% rename from io/fstream2.tmp rename to demo/io/fstream2.tmp diff --git a/io/ignore1.cpp b/demo/io/ignore1.cpp similarity index 100% rename from io/ignore1.cpp rename to demo/io/ignore1.cpp diff --git a/io/ignore1.hpp b/demo/io/ignore1.hpp similarity index 100% rename from io/ignore1.hpp rename to demo/io/ignore1.hpp diff --git a/io/ignore2.cpp b/demo/io/ignore2.cpp similarity index 100% rename from io/ignore2.cpp rename to demo/io/ignore2.cpp diff --git a/io/ignore2.hpp b/demo/io/ignore2.hpp similarity index 100% rename from io/ignore2.hpp rename to demo/io/ignore2.hpp diff --git a/io/inbuf1.cpp b/demo/io/inbuf1.cpp similarity index 100% rename from io/inbuf1.cpp rename to demo/io/inbuf1.cpp diff --git a/io/inbuf1.hpp b/demo/io/inbuf1.hpp similarity index 100% rename from io/inbuf1.hpp rename to demo/io/inbuf1.hpp diff --git a/io/io1.cpp b/demo/io/io1.cpp similarity index 100% rename from io/io1.cpp rename to demo/io/io1.cpp diff --git a/io/outbuf1.cpp b/demo/io/outbuf1.cpp similarity index 100% rename from io/outbuf1.cpp rename to demo/io/outbuf1.cpp diff --git a/io/outbuf1.hpp b/demo/io/outbuf1.hpp similarity index 100% rename from io/outbuf1.hpp rename to demo/io/outbuf1.hpp diff --git a/io/outbuf1i18n.cpp b/demo/io/outbuf1i18n.cpp similarity index 100% rename from io/outbuf1i18n.cpp rename to demo/io/outbuf1i18n.cpp diff --git a/io/outbuf1i18n.hpp b/demo/io/outbuf1i18n.hpp similarity index 100% rename from io/outbuf1i18n.hpp rename to demo/io/outbuf1i18n.hpp diff --git a/io/outbuf2.cpp b/demo/io/outbuf2.cpp similarity index 100% rename from io/outbuf2.cpp rename to demo/io/outbuf2.cpp diff --git a/io/outbuf2.hpp b/demo/io/outbuf2.hpp similarity index 100% rename from io/outbuf2.hpp rename to demo/io/outbuf2.hpp diff --git a/io/outbuf3.cpp b/demo/io/outbuf3.cpp similarity index 100% rename from io/outbuf3.cpp rename to demo/io/outbuf3.cpp diff --git a/io/outbuf3.hpp b/demo/io/outbuf3.hpp similarity index 100% rename from io/outbuf3.hpp rename to demo/io/outbuf3.hpp diff --git a/io/redirect.txt b/demo/io/redirect.txt similarity index 100% rename from io/redirect.txt rename to demo/io/redirect.txt diff --git a/io/sstream1.cpp b/demo/io/sstream1.cpp similarity index 100% rename from io/sstream1.cpp rename to demo/io/sstream1.cpp diff --git a/io/sstream2.cpp b/demo/io/sstream2.cpp similarity index 100% rename from io/sstream2.cpp rename to demo/io/sstream2.cpp diff --git a/io/streambuffer1.cpp b/demo/io/streambuffer1.cpp similarity index 100% rename from io/streambuffer1.cpp rename to demo/io/streambuffer1.cpp diff --git a/io/streambuffer2.cpp b/demo/io/streambuffer2.cpp similarity index 100% rename from io/streambuffer2.cpp rename to demo/io/streambuffer2.cpp diff --git a/io/streamreadwrite1.cpp b/demo/io/streamreadwrite1.cpp similarity index 100% rename from io/streamreadwrite1.cpp rename to demo/io/streamreadwrite1.cpp diff --git a/io/streamredirect1.cpp b/demo/io/streamredirect1.cpp similarity index 100% rename from io/streamredirect1.cpp rename to demo/io/streamredirect1.cpp diff --git a/io/sum1.cpp b/demo/io/sum1.cpp similarity index 100% rename from io/sum1.cpp rename to demo/io/sum1.cpp diff --git a/io/sum2.cpp b/demo/io/sum2.cpp similarity index 100% rename from io/sum2.cpp rename to demo/io/sum2.cpp diff --git a/io/timemanipulator1.cpp b/demo/io/timemanipulator1.cpp similarity index 100% rename from io/timemanipulator1.cpp rename to demo/io/timemanipulator1.cpp diff --git a/iter/advance1.cpp b/demo/iter/advance1.cpp similarity index 100% rename from iter/advance1.cpp rename to demo/iter/advance1.cpp diff --git a/iter/advance2.cpp b/demo/iter/advance2.cpp similarity index 100% rename from iter/advance2.cpp rename to demo/iter/advance2.cpp diff --git a/iter/assoiter.hpp b/demo/iter/assoiter.hpp similarity index 100% rename from iter/assoiter.hpp rename to demo/iter/assoiter.hpp diff --git a/iter/assoiter1.cpp b/demo/iter/assoiter1.cpp similarity index 100% rename from iter/assoiter1.cpp rename to demo/iter/assoiter1.cpp diff --git a/iter/backinserter1.cpp b/demo/iter/backinserter1.cpp similarity index 100% rename from iter/backinserter1.cpp rename to demo/iter/backinserter1.cpp diff --git a/iter/distance1.cpp b/demo/iter/distance1.cpp similarity index 100% rename from iter/distance1.cpp rename to demo/iter/distance1.cpp diff --git a/iter/frontinserter1.cpp b/demo/iter/frontinserter1.cpp similarity index 100% rename from iter/frontinserter1.cpp rename to demo/iter/frontinserter1.cpp diff --git a/iter/inserter1.cpp b/demo/iter/inserter1.cpp similarity index 100% rename from iter/inserter1.cpp rename to demo/iter/inserter1.cpp diff --git a/iter/istreamiter1.cpp b/demo/iter/istreamiter1.cpp similarity index 100% rename from iter/istreamiter1.cpp rename to demo/iter/istreamiter1.cpp diff --git a/iter/itercategory1.cpp b/demo/iter/itercategory1.cpp similarity index 100% rename from iter/itercategory1.cpp rename to demo/iter/itercategory1.cpp diff --git a/iter/iterswap1.cpp b/demo/iter/iterswap1.cpp similarity index 100% rename from iter/iterswap1.cpp rename to demo/iter/iterswap1.cpp diff --git a/iter/ostreamiter1.cpp b/demo/iter/ostreamiter1.cpp similarity index 100% rename from iter/ostreamiter1.cpp rename to demo/iter/ostreamiter1.cpp diff --git a/iter/print.hpp b/demo/iter/print.hpp similarity index 100% rename from iter/print.hpp rename to demo/iter/print.hpp diff --git a/iter/reviter1.cpp b/demo/iter/reviter1.cpp similarity index 100% rename from iter/reviter1.cpp rename to demo/iter/reviter1.cpp diff --git a/iter/reviter2.cpp b/demo/iter/reviter2.cpp similarity index 100% rename from iter/reviter2.cpp rename to demo/iter/reviter2.cpp diff --git a/iter/reviter3.cpp b/demo/iter/reviter3.cpp similarity index 100% rename from iter/reviter3.cpp rename to demo/iter/reviter3.cpp diff --git a/iter/reviter4.cpp b/demo/iter/reviter4.cpp similarity index 100% rename from iter/reviter4.cpp rename to demo/iter/reviter4.cpp diff --git a/lang/lambda1.cpp b/demo/lang/lambda1.cpp similarity index 100% rename from lang/lambda1.cpp rename to demo/lang/lambda1.cpp diff --git a/num/complex1.cpp b/demo/num/complex1.cpp similarity index 100% rename from num/complex1.cpp rename to demo/num/complex1.cpp diff --git a/num/complex2.cpp b/demo/num/complex2.cpp similarity index 100% rename from num/complex2.cpp rename to demo/num/complex2.cpp diff --git a/num/dist1.cpp b/demo/num/dist1.cpp similarity index 100% rename from num/dist1.cpp rename to demo/num/dist1.cpp diff --git a/num/gslice1.cpp b/demo/num/gslice1.cpp similarity index 100% rename from num/gslice1.cpp rename to demo/num/gslice1.cpp diff --git a/num/indirectarray1.cpp b/demo/num/indirectarray1.cpp similarity index 100% rename from num/indirectarray1.cpp rename to demo/num/indirectarray1.cpp diff --git a/num/maskarray1.cpp b/demo/num/maskarray1.cpp similarity index 100% rename from num/maskarray1.cpp rename to demo/num/maskarray1.cpp diff --git a/num/random1.cpp b/demo/num/random1.cpp similarity index 100% rename from num/random1.cpp rename to demo/num/random1.cpp diff --git a/num/random2.cpp b/demo/num/random2.cpp similarity index 100% rename from num/random2.cpp rename to demo/num/random2.cpp diff --git a/num/slice1.cpp b/demo/num/slice1.cpp similarity index 100% rename from num/slice1.cpp rename to demo/num/slice1.cpp diff --git a/num/valarray1.cpp b/demo/num/valarray1.cpp similarity index 100% rename from num/valarray1.cpp rename to demo/num/valarray1.cpp diff --git a/num/valarray2.cpp b/demo/num/valarray2.cpp similarity index 100% rename from num/valarray2.cpp rename to demo/num/valarray2.cpp diff --git a/regex/regex1.cpp b/demo/regex/regex1.cpp similarity index 100% rename from regex/regex1.cpp rename to demo/regex/regex1.cpp diff --git a/regex/regex2.cpp b/demo/regex/regex2.cpp similarity index 100% rename from regex/regex2.cpp rename to demo/regex/regex2.cpp diff --git a/regex/regex3.cpp b/demo/regex/regex3.cpp similarity index 100% rename from regex/regex3.cpp rename to demo/regex/regex3.cpp diff --git a/regex/regex4.cpp b/demo/regex/regex4.cpp similarity index 100% rename from regex/regex4.cpp rename to demo/regex/regex4.cpp diff --git a/regex/regex5.cpp b/demo/regex/regex5.cpp similarity index 100% rename from regex/regex5.cpp rename to demo/regex/regex5.cpp diff --git a/regex/regexexception.hpp b/demo/regex/regexexception.hpp similarity index 100% rename from regex/regexexception.hpp rename to demo/regex/regexexception.hpp diff --git a/regex/regexiter1.cpp b/demo/regex/regexiter1.cpp similarity index 100% rename from regex/regexiter1.cpp rename to demo/regex/regexiter1.cpp diff --git a/regex/regextokeniter1.cpp b/demo/regex/regextokeniter1.cpp similarity index 100% rename from regex/regextokeniter1.cpp rename to demo/regex/regextokeniter1.cpp diff --git a/stl/add1.cpp b/demo/stl/add1.cpp similarity index 100% rename from stl/add1.cpp rename to demo/stl/add1.cpp diff --git a/stl/algo1.cpp b/demo/stl/algo1.cpp similarity index 100% rename from stl/algo1.cpp rename to demo/stl/algo1.cpp diff --git a/stl/algo1old.cpp b/demo/stl/algo1old.cpp similarity index 100% rename from stl/algo1old.cpp rename to demo/stl/algo1old.cpp diff --git a/stl/array1.cpp b/demo/stl/array1.cpp similarity index 100% rename from stl/array1.cpp rename to demo/stl/array1.cpp diff --git a/stl/assoarray1.cpp b/demo/stl/assoarray1.cpp similarity index 100% rename from stl/assoarray1.cpp rename to demo/stl/assoarray1.cpp diff --git a/stl/bind1.cpp b/demo/stl/bind1.cpp similarity index 100% rename from stl/bind1.cpp rename to demo/stl/bind1.cpp diff --git a/stl/copy1.cpp b/demo/stl/copy1.cpp similarity index 100% rename from stl/copy1.cpp rename to demo/stl/copy1.cpp diff --git a/stl/copy2.cpp b/demo/stl/copy2.cpp similarity index 100% rename from stl/copy2.cpp rename to demo/stl/copy2.cpp diff --git a/stl/copybug.cpp b/demo/stl/copybug.cpp similarity index 100% rename from stl/copybug.cpp rename to demo/stl/copybug.cpp diff --git a/stl/deque1.cpp b/demo/stl/deque1.cpp similarity index 100% rename from stl/deque1.cpp rename to demo/stl/deque1.cpp diff --git a/stl/find1.cpp b/demo/stl/find1.cpp similarity index 100% rename from stl/find1.cpp rename to demo/stl/find1.cpp diff --git a/stl/fo1.cpp b/demo/stl/fo1.cpp similarity index 100% rename from stl/fo1.cpp rename to demo/stl/fo1.cpp diff --git a/stl/foreach1.cpp b/demo/stl/foreach1.cpp similarity index 100% rename from stl/foreach1.cpp rename to demo/stl/foreach1.cpp diff --git a/stl/foreach2.cpp b/demo/stl/foreach2.cpp similarity index 100% rename from stl/foreach2.cpp rename to demo/stl/foreach2.cpp diff --git a/stl/forwardlist1.cpp b/demo/stl/forwardlist1.cpp similarity index 100% rename from stl/forwardlist1.cpp rename to demo/stl/forwardlist1.cpp diff --git a/stl/ioiter1.cpp b/demo/stl/ioiter1.cpp similarity index 100% rename from stl/ioiter1.cpp rename to demo/stl/ioiter1.cpp diff --git a/stl/iterbug.cpp b/demo/stl/iterbug.cpp similarity index 100% rename from stl/iterbug.cpp rename to demo/stl/iterbug.cpp diff --git a/stl/lambda1.cpp b/demo/stl/lambda1.cpp similarity index 100% rename from stl/lambda1.cpp rename to demo/stl/lambda1.cpp diff --git a/stl/list1.cpp b/demo/stl/list1.cpp similarity index 100% rename from stl/list1.cpp rename to demo/stl/list1.cpp diff --git a/stl/list1old.cpp b/demo/stl/list1old.cpp similarity index 100% rename from stl/list1old.cpp rename to demo/stl/list1old.cpp diff --git a/stl/list2.cpp b/demo/stl/list2.cpp similarity index 100% rename from stl/list2.cpp rename to demo/stl/list2.cpp diff --git a/stl/multimap1.cpp b/demo/stl/multimap1.cpp similarity index 100% rename from stl/multimap1.cpp rename to demo/stl/multimap1.cpp diff --git a/stl/multiset1.cpp b/demo/stl/multiset1.cpp similarity index 100% rename from stl/multiset1.cpp rename to demo/stl/multiset1.cpp diff --git a/stl/prime1.cpp b/demo/stl/prime1.cpp similarity index 100% rename from stl/prime1.cpp rename to demo/stl/prime1.cpp diff --git a/stl/print.hpp b/demo/stl/print.hpp similarity index 100% rename from stl/print.hpp rename to demo/stl/print.hpp diff --git a/stl/remove1.cpp b/demo/stl/remove1.cpp similarity index 100% rename from stl/remove1.cpp rename to demo/stl/remove1.cpp diff --git a/stl/remove2.cpp b/demo/stl/remove2.cpp similarity index 100% rename from stl/remove2.cpp rename to demo/stl/remove2.cpp diff --git a/stl/remove3.cpp b/demo/stl/remove3.cpp similarity index 100% rename from stl/remove3.cpp rename to demo/stl/remove3.cpp diff --git a/stl/remove4.cpp b/demo/stl/remove4.cpp similarity index 100% rename from stl/remove4.cpp rename to demo/stl/remove4.cpp diff --git a/stl/reviter1.cpp b/demo/stl/reviter1.cpp similarity index 100% rename from stl/reviter1.cpp rename to demo/stl/reviter1.cpp diff --git a/stl/set1.cpp b/demo/stl/set1.cpp similarity index 100% rename from stl/set1.cpp rename to demo/stl/set1.cpp diff --git a/stl/sort1.cpp b/demo/stl/sort1.cpp similarity index 100% rename from stl/sort1.cpp rename to demo/stl/sort1.cpp diff --git a/stl/sort2.cpp b/demo/stl/sort2.cpp similarity index 100% rename from stl/sort2.cpp rename to demo/stl/sort2.cpp diff --git a/stl/transform1.cpp b/demo/stl/transform1.cpp similarity index 100% rename from stl/transform1.cpp rename to demo/stl/transform1.cpp diff --git a/stl/unordmap1.cpp b/demo/stl/unordmap1.cpp similarity index 100% rename from stl/unordmap1.cpp rename to demo/stl/unordmap1.cpp diff --git a/stl/unordmultiset1.cpp b/demo/stl/unordmultiset1.cpp similarity index 100% rename from stl/unordmultiset1.cpp rename to demo/stl/unordmultiset1.cpp diff --git a/stl/unordmultiset2.cpp b/demo/stl/unordmultiset2.cpp similarity index 100% rename from stl/unordmultiset2.cpp rename to demo/stl/unordmultiset2.cpp diff --git a/stl/vector1.cpp b/demo/stl/vector1.cpp similarity index 100% rename from stl/vector1.cpp rename to demo/stl/vector1.cpp diff --git a/string/icstring.hpp b/demo/string/icstring.hpp similarity index 100% rename from string/icstring.hpp rename to demo/string/icstring.hpp diff --git a/string/icstring1.cpp b/demo/string/icstring1.cpp similarity index 100% rename from string/icstring1.cpp rename to demo/string/icstring1.cpp diff --git a/string/string1.cpp b/demo/string/string1.cpp similarity index 100% rename from string/string1.cpp rename to demo/string/string1.cpp diff --git a/string/string2.cpp b/demo/string/string2.cpp similarity index 100% rename from string/string2.cpp rename to demo/string/string2.cpp diff --git a/string/string3.cpp b/demo/string/string3.cpp similarity index 100% rename from string/string3.cpp rename to demo/string/string3.cpp diff --git a/string/stringiter1.cpp b/demo/string/stringiter1.cpp similarity index 100% rename from string/stringiter1.cpp rename to demo/string/stringiter1.cpp diff --git a/string/stringiter2.cpp b/demo/string/stringiter2.cpp similarity index 100% rename from string/stringiter2.cpp rename to demo/string/stringiter2.cpp diff --git a/string/stringnumconv1.cpp b/demo/string/stringnumconv1.cpp similarity index 100% rename from string/stringnumconv1.cpp rename to demo/string/stringnumconv1.cpp diff --git a/util/chrono1.cpp b/demo/util/chrono1.cpp similarity index 100% rename from util/chrono1.cpp rename to demo/util/chrono1.cpp diff --git a/util/chrono2.cpp b/demo/util/chrono2.cpp similarity index 100% rename from util/chrono2.cpp rename to demo/util/chrono2.cpp diff --git a/util/clock.hpp b/demo/util/clock.hpp similarity index 100% rename from util/clock.hpp rename to demo/util/clock.hpp diff --git a/util/clock1.cpp b/demo/util/clock1.cpp similarity index 100% rename from util/clock1.cpp rename to demo/util/clock1.cpp diff --git a/util/enableshared1.cpp b/demo/util/enableshared1.cpp similarity index 100% rename from util/enableshared1.cpp rename to demo/util/enableshared1.cpp diff --git a/util/exception.hpp b/demo/util/exception.hpp similarity index 100% rename from util/exception.hpp rename to demo/util/exception.hpp diff --git a/util/limits1.cpp b/demo/util/limits1.cpp similarity index 100% rename from util/limits1.cpp rename to demo/util/limits1.cpp diff --git a/util/minmax1.cpp b/demo/util/minmax1.cpp similarity index 100% rename from util/minmax1.cpp rename to demo/util/minmax1.cpp diff --git a/util/pair1.cpp b/demo/util/pair1.cpp similarity index 100% rename from util/pair1.cpp rename to demo/util/pair1.cpp diff --git a/util/printtuple.hpp b/demo/util/printtuple.hpp similarity index 100% rename from util/printtuple.hpp rename to demo/util/printtuple.hpp diff --git a/util/ratio1.cpp b/demo/util/ratio1.cpp similarity index 100% rename from util/ratio1.cpp rename to demo/util/ratio1.cpp diff --git a/util/sharedptr1.cpp b/demo/util/sharedptr1.cpp similarity index 100% rename from util/sharedptr1.cpp rename to demo/util/sharedptr1.cpp diff --git a/util/sharedptr2.cpp b/demo/util/sharedptr2.cpp similarity index 100% rename from util/sharedptr2.cpp rename to demo/util/sharedptr2.cpp diff --git a/util/sharedptr3.cpp b/demo/util/sharedptr3.cpp similarity index 100% rename from util/sharedptr3.cpp rename to demo/util/sharedptr3.cpp diff --git a/util/timepoint.hpp b/demo/util/timepoint.hpp similarity index 100% rename from util/timepoint.hpp rename to demo/util/timepoint.hpp diff --git a/util/timepoint1.cpp b/demo/util/timepoint1.cpp similarity index 100% rename from util/timepoint1.cpp rename to demo/util/timepoint1.cpp diff --git a/util/tuple1.cpp b/demo/util/tuple1.cpp similarity index 100% rename from util/tuple1.cpp rename to demo/util/tuple1.cpp diff --git a/util/tuple2.cpp b/demo/util/tuple2.cpp similarity index 100% rename from util/tuple2.cpp rename to demo/util/tuple2.cpp diff --git a/util/uniqueptr1.cpp b/demo/util/uniqueptr1.cpp similarity index 100% rename from util/uniqueptr1.cpp rename to demo/util/uniqueptr1.cpp diff --git a/util/weakptr1.cpp b/demo/util/weakptr1.cpp similarity index 100% rename from util/weakptr1.cpp rename to demo/util/weakptr1.cpp diff --git a/util/weakptr2.cpp b/demo/util/weakptr2.cpp similarity index 100% rename from util/weakptr2.cpp rename to demo/util/weakptr2.cpp diff --git a/include/accumulate.h b/include/accumulate.h new file mode 100644 index 0000000000000000000000000000000000000000..4206d89b01cf2faa251bc2fbb929e95081073161 --- /dev/null +++ b/include/accumulate.h @@ -0,0 +1,38 @@ +#pragma once +#include "algostuff.h" +using namespace std; + +void test_accumulate() { + vector coll; + + INSERT_ELEMENTS(coll, 1, 9); + + std::cout << "value " << std::endl; + PRINT_ELEMENTS(coll); + + // process sum of elements + cout << "sum: " + << accumulate(coll.cbegin(), coll.cend(), // range + 0) // initial value + << endl; + + // process sum of elements less 100 + cout << "sum: " + << accumulate(coll.cbegin(), coll.cend(), // range + -100) // initial value + << endl; + + // process product of elements + cout << "product: " + << accumulate(coll.cbegin(), coll.cend(), // range + 1, // initial value + multiplies()) // operation + << endl; + + // process product of elements (use 0 as initial value) + cout << "product: " + << accumulate(coll.cbegin(), coll.cend(), // range + 0, // initial value + multiplies()) // operation + << endl; +} \ No newline at end of file diff --git a/include/algostuff.h b/include/algostuff.h new file mode 100644 index 0000000000000000000000000000000000000000..fd7ae2057803e0dfb49df5c91412ef87158b33e6 --- /dev/null +++ b/include/algostuff.h @@ -0,0 +1,75 @@ +/* The following code example is taken from the book + * "The C++ Standard Library - A Tutorial and Reference, 2nd Edition" + * by Nicolai M. Josuttis, Addison-Wesley, 2012 + * + * (C) Copyright Nicolai M. Josuttis 2012. + * Permission to copy, use, modify, sell and distribute this software + * is granted provided this copyright notice appears in all copies. + * This software is provided "as is" without express or implied + * warranty, and with no claim as to its suitability for any purpose. + */ +#ifndef ALGOSTUFF_HPP +#define ALGOSTUFF_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// INSERT_ELEMENTS (collection, first, last) +// - fill values from first to last into the collection +// - NOTE: NO half-open range +template +inline void INSERT_ELEMENTS(T &coll, int first, int last) +{ + for (int i = first; i <= last; ++i) + { + coll.insert(coll.end(), i); + } +} + +// PRINT_ELEMENTS() +// - prints optional string optcstr followed by +// - all elements of the collection coll +// - separated by spaces +template +inline void PRINT_ELEMENTS(const T &coll, + const std::string &optcstr = "") +{ + std::cout << optcstr; + for (auto elem : coll) + { + std::cout << elem << ' '; + } + std::cout << std::endl; +} + +// PRINT_MAPPED_ELEMENTS() +// - prints optional string optcstr followed by +// - all elements of the key/value collection coll +// - separated by spaces +template +inline void PRINT_MAPPED_ELEMENTS(const T &coll, + const std::string &optcstr = "") +{ + std::cout << optcstr; + for (auto elem : coll) + { + std::cout << '[' << elem.first + << ',' << elem.second << "] "; + } + std::cout << std::endl; +} + +#endif /*ALGOSTUFF_HPP*/ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..35e4dca540fbb9ed98db565a32aee96b0c1c566b --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,9 @@ +# STL_LIB +# find_library(STL_LIB stdc++ REQUIRED) + +# 可执行文件 +add_executable(StlFuncs main.cpp) + +target_include_directories(StlFuncs PUBLIC include) +# 链接 +# target_link_libraries(StlFuncs PRIVATE ${STL_LIB}) \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..57da64f4bc133db433abccf58052cfc7a1780e39 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,47 @@ +/* The following code example is taken from the book + * "The C++ Standard Library - A Tutorial and Reference, 2nd Edition" + * by Nicolai M. Josuttis, Addison-Wesley, 2012 + * + * (C) Copyright Nicolai M. Josuttis 2012. + * Permission to copy, use, modify, sell and distribute this software + * is granted provided this copyright notice appears in all copies. + * This software is provided "as is" without express or implied + * warranty, and with no claim as to its suitability for any purpose. + */ + #include "algostuff.h" + using namespace std; + + int main() + { + vector coll; + + INSERT_ELEMENTS(coll, 1, 9); + PRINT_ELEMENTS(coll); + + // process sum of elements + cout << "sum: " + << accumulate(coll.cbegin(), coll.cend(), // range + 0) // initial value + << endl; + + // process sum of elements less 100 + cout << "sum: " + << accumulate(coll.cbegin(), coll.cend(), // range + -100) // initial value + << endl; + + // process product of elements + cout << "product: " + << accumulate(coll.cbegin(), coll.cend(), // range + 1, // initial value + multiplies()) // operation + << endl; + + // process product of elements (use 0 as initial value) + cout << "product: " + << accumulate(coll.cbegin(), coll.cend(), // range + 0, // initial value + multiplies()) // operation + << endl; + } + \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5e0ae37152969b9fc7d78d5da1e94e55ab83ff1c --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,16 @@ +# tests/CMakeLists.txt +find_package(GTest REQUIRED) + + +include_directories(${GTEST_INCLUDE_DIRS}) + +# 添加测试可执行文件 +add_executable(CiTest test_main.cpp) + +if(GTest_FOUND) + include_directories(${GTEST_INCLUDE_DIRS}) + target_link_libraries(CiTest ${GTEST_LIBRARIES} pthread) +endif() + +# 添加测试 +add_test(NAME CiTest COMMAND test) \ No newline at end of file diff --git a/tests/test_main.cpp b/tests/test_main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0078efcf238a602c5ace66b297ac5fc7024f0d89 --- /dev/null +++ b/tests/test_main.cpp @@ -0,0 +1,14 @@ +#include +#include "accumulate.h" + +TEST(AddTest, PositiveNumbers) { + test_accumulate(); + EXPECT_EQ(3, 3); +} + +TEST(AddTest, NegativeNumbers) { EXPECT_EQ(-3, -3); } + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}