├── ws04 ├── move_enabled │ ├── .gitignore │ └── README.md ├── chapter_function_syntax_move_ctor │ ├── .gitignore │ └── factoryfunction.cpp ├── chapter_function_syntax_test │ └── hello.txt ├── chapter_function_syntax │ ├── README.md │ ├── overload.h │ ├── overload.cpp │ ├── defaultargument.h │ ├── defaultargument.cpp │ ├── hello.txt │ ├── returnreference.cpp │ └── factorial.cpp ├── exception_syntax │ ├── README.md │ ├── noexcept.cpp │ └── standardexcept.cpp ├── main_try_catch │ ├── main_try_catch.cpp │ └── README.md ├── namespacesyntax │ ├── README.md │ ├── demoanonymous.cpp │ ├── anonymousnamespace.cpp │ └── namespacesyntax.cpp ├── exception_testing │ ├── src │ │ ├── squareroot.h │ │ └── squareroot.cpp │ └── README.md ├── move_overload_demo │ └── README.md ├── move_only │ └── README.md └── chapter_function_syntax_lib │ └── long_function.h ├── exws11 ├── squares │ ├── .gitignore │ └── src │ │ ├── squares.h │ │ └── squares.cpp ├── readln │ └── src │ │ └── readln.h ├── median │ └── src │ │ └── median.h └── rotate3arguments │ └── src │ └── rotate3arguments.h ├── solws08 ├── anagram_multiword │ ├── .gitignore │ └── README.md ├── anagram_multiword_opt │ ├── .gitignore │ └── README.md ├── anagram │ └── README.md └── palindrome │ └── palindrome.cpp ├── CppAdvanced ├── cpla_ws11 │ ├── multiplication_table │ │ └── .suppressed │ ├── ratio_demo │ │ └── src │ │ │ └── .vscode │ │ │ └── .browse.VC.db │ ├── fibo_sequence │ │ └── fibo_sequence.xml │ ├── BoundedQueue │ │ └── src │ │ │ ├── bounded_queue_content_suite.h │ │ │ ├── bounded_queue_semantic_suite.h │ │ │ ├── bounded_queue_signatures_suite.h │ │ │ ├── bounded_queue_student_suite.h │ │ │ ├── bounded_queue_heap_memory_suite.h │ │ │ ├── bounded_queue_multi_threaded_suite.h │ │ │ ├── bounded_queue_default_behavior_suite.h │ │ │ ├── bounded_queue_single_threaded_lock_suite.h │ │ │ ├── bounded_queue_student_suite.cpp │ │ │ ├── bounded_queue_non_default_constructible_element_type_suite.h │ │ │ └── times_literal.hpp │ ├── inheritance_SFINAE_example │ │ └── src │ │ │ └── inheritance_SFINAE_example.cpp │ ├── multiplication_table_loops │ │ └── src │ │ │ └── multiplication_table_loops.cpp │ ├── Tailor │ │ └── Tailor.xml │ └── Cpp14MultiplicationTableCompileTimeAsString │ │ └── Cpp14MultiplicationTableCompileTimeAsString.xml ├── other │ ├── old_w7 │ │ ├── multiplication_table │ │ │ └── .suppressed │ │ ├── LiteralTypesAndUDL │ │ │ ├── LiteralTypesAndUDL.xml │ │ │ └── src │ │ │ │ └── Test.cpp │ │ ├── Cpp14CompileTimeComputation │ │ │ └── Cpp14CompileTimeComputation.xml │ │ ├── Cpp03compileTimeComputation │ │ │ └── Cpp03compileTimeComputation.xml │ │ ├── multiplication_table_loops │ │ │ └── src │ │ │ │ └── multiplication_table_loops.cpp │ │ ├── Cpp11compileTimeComputation │ │ │ └── Cpp11compileTimeComputation.xml │ │ ├── array_std_array │ │ │ └── array_std_array.cpp │ │ ├── Fibo_CPP14_constexpr │ │ │ └── Fibo_CPP14_constexpr.xml │ │ ├── Tailor │ │ │ └── Tailor.xml │ │ ├── FizzBuzzVariadicClassSingleDigit │ │ │ ├── FizzBuzzVariadicClassSingleDigit.xml │ │ │ └── FizzBuzzVariadicClass.xml │ │ ├── Fibo_CPP03 │ │ │ ├── src │ │ │ │ └── Fibo.h │ │ │ └── Fibo_CPP03.xml │ │ ├── FizzBuzzVariadicClass │ │ │ └── FizzBuzzVariadicClass.xml │ │ ├── fac_from_integral_constant │ │ │ └── fac_from_integral_constant.cpp │ │ ├── fac_constexpr_run_time_error │ │ │ └── fc.cpp │ │ ├── FizzBuzzVariadicClassComplete │ │ │ └── FizzBuzzVariadicClassComplete.xml │ │ ├── NonTypeTemplateExample │ │ │ └── NonTypeTemplate.cpp │ │ ├── FizzBuzzVariadic │ │ │ ├── FizzBuzzVariadic.xml │ │ │ └── src │ │ │ │ └── println.h │ │ ├── FizzBuzzVariadicNonRecursive │ │ │ ├── FizzBuzzVariadic.xml │ │ │ ├── FizzBuzzVariadicNonRecursive.xml │ │ │ └── src │ │ │ │ └── println.h │ │ ├── fac_prohibit_run_time_call │ │ │ └── fac_prohibit_run_time_call.cpp │ │ └── Cpp14MultiplicationTableCompileTimeAsString │ │ │ └── Cpp14MultiplicationTableCompileTimeAsString.xml │ ├── old_w6 │ │ ├── FibonacciIterator │ │ │ └── src │ │ │ │ └── FibonacciIterator.h │ │ ├── iteratorboost │ │ │ └── intiteratorboost.cpp │ │ └── intiteratorboost │ │ │ └── intiteratorboost.cpp │ ├── user_defined_literals │ │ ├── src │ │ │ └── velocity.hpp │ │ └── user_defined_literals.xml │ ├── user_defined_literals_ambiguity_s │ │ └── main.cpp │ ├── user_defined_literals_string │ │ └── main.cpp │ └── user_defined_literals_ternary │ │ └── main.cpp ├── cpla_ws10 │ ├── BoundedQueue │ │ └── src │ │ │ ├── .gitignore │ │ │ ├── TestBoundedQueueAPI.h │ │ │ ├── bounded_queue_content_suite.h │ │ │ ├── TestBoundedQueueAPI.cpp │ │ │ ├── bounded_queue_semantic_suite.h │ │ │ ├── bounded_queue_signatures_suite.h │ │ │ ├── bounded_queue_student_suite.h │ │ │ ├── bounded_queue_heap_memory_suite.h │ │ │ ├── bounded_queue_multi_threaded_suite.h │ │ │ ├── bounded_queue_default_behavior_suite.h │ │ │ ├── bounded_queue_single_threaded_lock_suite.h │ │ │ ├── bounded_queue_student_suite.cpp │ │ │ ├── bounded_queue_non_default_constructible_element_type_suite.h │ │ │ └── times_literal.hpp │ ├── SimpleThreadGotcha │ │ └── src │ │ │ └── SimpleThreadGotcha.cpp │ ├── SimpleThreadExample │ │ └── src │ │ │ └── SimpleThreadExample.cpp │ ├── SimpleThisThreadExample │ │ └── src │ │ │ └── SimpleThisThreadExample.cpp │ ├── SimpleThreadDetach │ │ └── src │ │ │ └── SimpleThreadDetach.cpp │ ├── SimpleThreadDetachDanger │ │ └── src │ │ │ └── SimpleThreadDetachDanger.cpp │ ├── AtomicFlagExample │ │ └── AtomicFlagExample.cpp │ ├── AtomicsAreLockFree │ │ └── AtomicsAreLockFree.cpp │ └── SimpleThreadWrapper │ │ └── src │ │ └── ScopedThreadExample.cpp ├── cpla_ws07 │ ├── BoundedBufferTestat │ │ └── src │ │ │ ├── .gitignore │ │ │ ├── bounded_buffer_content_suite.h │ │ │ ├── bounded_buffer_iterator_suite.h │ │ │ ├── bounded_buffer_semantic_suite.h │ │ │ ├── bounded_buffer_signatures_suite.h │ │ │ ├── bounded_buffer_student_suite.h │ │ │ ├── bounded_buffer_default_behavior_suite.h │ │ │ ├── bounded_buffer_heap_memory_suite.h │ │ │ ├── bounded_buffer_student_suite.cpp │ │ │ ├── bounded_buffer_non_default_constructible_element_type_suite.h │ │ │ └── n_times.h │ ├── 07_02_extract_middle │ │ └── main.cpp │ ├── 07_03_arbitrary_printer │ │ └── main.cpp │ └── 07_00_shape_and_square │ │ └── shape_and_square.cpp ├── cpla_ws09 │ ├── BoundedBufferArray │ │ └── src │ │ │ ├── .gitignore │ │ │ ├── bounded_buffer_content_suite.h │ │ │ ├── bounded_buffer_semantic_suite.h │ │ │ ├── bounded_buffer_signatures_suite.h │ │ │ ├── bounded_buffer_student_suite.h │ │ │ ├── bounded_buffer_default_behavior_suite.h │ │ │ ├── bounded_buffer_content_suite_no_default.h │ │ │ ├── bounded_buffer_semantic_suite_no_default.h │ │ │ └── n_times.h │ ├── DemoSpecialExceptionSituations │ │ └── DemoSpecialExceptionSituations.xml │ ├── DemoTerminate │ │ └── main.cpp │ └── ExplosiveLiquid │ │ └── random.h ├── cpla_sol_ws01 │ ├── ex01_fraction_type │ │ └── .gitignore │ └── ex01_simple_tasks │ │ └── .gitignore ├── cpla_ws14 │ ├── hello │ │ └── hello.cpp │ ├── lessthan │ │ ├── lessthan.h │ │ └── lessthan.cpp │ ├── iterator │ │ └── iterator.cpp │ ├── non_addable │ │ └── non_addable.cpp │ ├── addable │ │ └── addable.cpp │ ├── unary_concept │ │ └── unary_concept.cpp │ └── addable_member │ │ └── addable_member.cpp ├── cpla_ws01 │ ├── 00_01_CtylecheckerDemo │ │ └── src │ │ │ ├── header.cpp │ │ │ └── header.h │ └── 00_02_IssuesInCevelop │ │ └── cpp17problems.cpp ├── cpla_ws12 │ ├── HairpollClient │ │ ├── README.md │ │ └── result.html │ ├── HairpollLib │ │ └── README.md │ ├── Wizard │ │ └── WizardIngredients.h │ ├── WizardCLib │ │ └── src │ │ │ └── WizardIngredients.h │ ├── WizardPimpl │ │ ├── src │ │ │ └── WizardIngredients.h │ │ └── Wizard.h │ └── UniversalOpaquePointerDemo │ │ └── src │ │ └── UniversalOpaquePointerDemo.cpp ├── cpla_ws13 │ ├── DemoOptional │ │ └── DemoOptional.xml │ ├── DemoPathWithUnicode │ │ └── src │ │ │ └── DemoPathWithUnicode.cpp │ └── DemoDir │ │ └── src │ │ └── DemoDir.cpp ├── cpla_ws04 │ ├── 04_06_initializer_list_as_template_argument │ │ └── main.cpp │ ├── 04_08_bad_decl_type │ │ └── main.cpp │ ├── 04_00_copy_demo │ │ └── main.cpp │ ├── 04_01_move_demo │ │ └── main.cpp │ ├── 04_02_elision │ │ └── main.cpp │ └── 04_05_overload_resolution_member_functions │ │ └── main.cpp ├── cpla_ws08 │ └── 08_02_traits_is_class │ │ └── src │ │ └── 08_02_traits_is_class.cpp ├── cpla_sol_ws02 │ ├── SolEx02_01_ExtensionsForDynArray │ │ └── Ex02_0x_DeductionForIndexableSet.exe.xml │ └── SolEx02_03_FoldRead │ │ ├── SolEx02_03_FoldRead.exe.xml │ │ └── src │ │ └── readln.h ├── cpla_ws02 │ ├── 02_05_optional_example │ │ └── 02_05_optional_example.exe.xml │ ├── 02_01_static_assert │ │ └── static_assert.cpp │ ├── 02_09_structured_binding │ │ └── structured_binding.cpp │ ├── 02_02_auto_specifier │ │ └── auto_specifier.cpp │ ├── 02_10_string_view │ │ └── string_view.cpp │ ├── 02_03_any_lecture_example │ │ └── any.cpp │ └── 02_07_path_example │ │ └── path.cpp ├── cpla_ws12_values_empty_etc │ ├── UnitsAsAggregates │ │ └── UnitsAsAggregates.xml │ ├── Pointers │ │ └── Pointers.xml │ ├── WholeValue │ │ └── WholeValue.xml │ └── EmptyClasses │ │ └── EmptyClasses.xml ├── cpla_ws13_ref_poly │ └── Pointers │ │ └── Pointers.xml ├── cpla_ws06 │ ├── nullptr_vs_null │ │ └── main.cpp │ └── emplace │ │ └── main.cpp ├── cpla_ws03 │ ├── 03_05_temporary_materialization │ │ └── main.cpp │ ├── can_be_moved_from │ │ └── main.cpp │ ├── why_rvalue_might_be_on_the_lhs │ │ └── main.cpp │ ├── copy_elision_exceptions │ │ └── main.cpp │ ├── copy_and_move_semantics_example │ │ └── main.cpp │ └── copy_move_constructors │ │ └── main.cpp └── cpla_ws11b_MI │ ├── MI_Ambiguities │ └── MI_Ambiguities.cpp │ ├── MI_StrangersAndFriends │ └── MI_StrangersAndFriends.cpp │ └── MI_MixInInheritance_CRTP │ └── MI_MixInInheritance_CRTP.cpp ├── exws09 ├── wcount │ ├── .gitignore │ └── src │ │ ├── wcount.h │ │ └── wcount.cpp ├── wordle │ ├── .gitignore │ └── src │ │ ├── wordle.h │ │ └── wordle.cpp ├── wfavorite │ ├── .gitignore │ └── src │ │ ├── wfavorite.h │ │ └── wfavorite.cpp ├── algorithm_trivia │ ├── .gitignore │ └── src │ │ ├── set_algorithms.h │ │ ├── find_algorithms.h │ │ ├── heap_algorithms.h │ │ ├── sort_algorithms.h │ │ ├── min_max_algorithms.h │ │ ├── numeric_algorithms.h │ │ ├── partition_algorithms.h │ │ ├── sorted_sequence_algorithms.h │ │ ├── copy_and_replace_algorithms.h │ │ ├── fill_and_generate_algorithms.h │ │ ├── property_checking_algorithms.h │ │ └── remove_unique_rotate_algorithms.h ├── wdiffcount │ ├── .gitignore │ └── src │ │ ├── wdiffcount.h │ │ └── wdiffcount.cpp ├── prime_numbers │ ├── .gitignore │ └── src │ │ ├── primes.cpp │ │ └── primes.h └── README.md ├── exws10 ├── woccurrence │ ├── .gitignore │ └── src │ │ ├── woccurrence.h │ │ └── woccurrence.cpp └── wseventh │ └── src │ ├── wseventh.h │ └── wseventh.cpp ├── exws12 ├── indexable_set │ ├── .gitignore │ ├── .settings │ │ └── ch.hsr.ifs.cute.elevenator.prefs │ └── src │ │ └── indexableSet.h └── DynArray │ └── src │ └── dynArray.h ├── exws14 ├── BedShapesTest │ └── src │ │ ├── Shape.cpp │ │ ├── Diamond.cpp │ │ ├── Square.cpp │ │ ├── Triangle.cpp │ │ ├── Rectangle.cpp │ │ ├── BedFactory.cpp │ │ ├── shoppinglist.cpp │ │ ├── shoppinglist.h │ │ ├── BedFactory.h │ │ ├── Square.h │ │ ├── Triangle.h │ │ ├── Diamond.h │ │ ├── Shape.h │ │ └── Rectangle.h └── polymorphism │ └── main.cpp ├── solws09 ├── wcount_solution │ ├── .gitignore │ └── src │ │ ├── wcount.h │ │ └── wcount.cpp ├── wdiffcount_solution │ ├── .gitignore │ └── src │ │ ├── wdiffcount.h │ │ └── wdiffcount.cpp ├── wfavorite_solution │ ├── .gitignore │ ├── test_resources │ │ └── chapter_6.txt │ └── src │ │ └── wfavorite.h ├── prime_numbers_solution │ ├── .gitignore │ └── src │ │ └── primes.h └── wlist_ascending │ └── wlist.cpp ├── solws11 ├── median_solution │ ├── .gitignore │ └── src │ │ └── median.h ├── readln_solution │ └── .gitignore └── rotate3arguments_solution │ ├── .gitignore │ └── src │ └── rotate3arguments.h ├── ws08 ├── ex_time_container_performance │ ├── .gitignore │ ├── timer.h │ └── timer.cpp ├── demolambda │ └── main.cpp ├── mapcountwords │ └── countwords.cpp ├── unordered_example │ └── unorderedmap.cpp ├── setexample │ └── vowelsset.cpp ├── mapcountvowels │ └── countvowels.cpp ├── demo_accumulate_string │ └── accumulatestring.cpp ├── countvowelsmultiset │ └── countvowelsmultiset.cpp ├── unordered_mapcountvowels │ └── unorderedcountvowels.cpp ├── unorderedsetremovevowels │ └── removevowels.cpp ├── demorotate │ └── rotate.cpp ├── multisetexample │ └── sortedlistofwords.cpp ├── stack_and_queue_example │ └── stackqueue.cpp ├── squarespartial_sumtransform │ └── squares.cpp └── democopybackward │ └── copybackward.cpp ├── solws10 ├── squares_solution │ ├── .gitignore │ └── src │ │ ├── squares.h │ │ └── squares.cpp ├── wseventh_solution │ ├── .gitignore │ ├── test_resources │ │ └── chapter_6.txt │ └── src │ │ └── wseventh.h └── woccurrence_solution │ ├── .gitignore │ └── src │ └── woccurrence.h ├── ws05 ├── DateTest │ └── README.md ├── DateTestInitializers │ └── README.md ├── DateCheckSyntax │ └── main.cpp ├── DateTestWithBoostOperators │ └── README.md ├── MoveOnly │ └── README.md ├── RingModulo5InOutConversionTest │ └── README.md ├── DateTestWithEnumerationForMonths │ └── README.md ├── DateWithBoostOperators │ └── README.md ├── DateWithEnumerationForMonths │ └── README.md ├── DateInitializers │ └── README.md ├── README.md ├── Date │ ├── Date0.h │ ├── README.md │ ├── Date1.h │ └── Date2.h ├── RingModulo5Constexpr │ ├── Ring5.cpp │ └── README.md ├── RingModulo5InOutConversion │ ├── Ring5.cpp │ └── README.md ├── RingModulo5MixedArithmetic │ ├── Ring5.cpp │ └── README.md ├── RingModulo5ConstexprTest │ └── README.md ├── enumDemo │ ├── README.md │ ├── Statemachine.h │ └── Statemachine.cpp ├── TracerDemo │ └── README.md └── TracerMoveDemo │ └── README.md ├── solws04 ├── README.md ├── wlist_caseless │ └── README.md ├── FunctionValueTable │ ├── funcval.h │ └── README.md ├── wlist │ ├── README.md │ └── wlist.cpp └── countingToLower │ ├── README.md │ └── countingToLower.xml ├── ws01 ├── Hello │ ├── README.md │ ├── sayhello.cpp │ ├── Hello.cpp │ ├── sayhello.h │ └── Hello.h ├── README.md ├── HelloMain │ ├── README.md │ └── hellomain.cpp ├── HelloTest │ └── README.md └── helloworld │ ├── README.md │ └── helloworld.cpp ├── solws13 ├── topological_sort_fast │ ├── README.md │ ├── semester.h │ ├── semester_topological.h │ └── main.cpp ├── GardeningLibTest │ └── src │ │ ├── CircleSuite.h │ │ ├── SquareSuite.h │ │ ├── DiamondSuite.h │ │ ├── EllipseSuite.h │ │ ├── RectangleSuite.h │ │ ├── TriangleSuite.h │ │ └── PolymorphismSuite.h ├── topological_sort_main │ ├── README.md │ └── main.cpp ├── GardeningLib │ ├── Shapes.h │ └── Shapes │ │ ├── Shape.cpp │ │ ├── Circle.h │ │ ├── Square.h │ │ ├── Rectangle.h │ │ ├── Ellipse.h │ │ ├── Shape.h │ │ ├── Diamond.h │ │ └── Triangle.h ├── topological_sort_lib │ └── README.md ├── echor │ ├── README.md │ └── echor.cpp └── topological_sort │ └── topological_sort.xml ├── ws03 ├── README.md ├── algorithmdemo │ └── README.md ├── tolower │ ├── src │ │ └── tolower.cpp │ └── README.md ├── vectordemo │ ├── README.md │ └── vectordemo.cpp ├── copycat │ ├── copycat.cpp │ └── README.md └── cat │ ├── cat.cpp │ └── README.md ├── solws06 ├── DateTestWithEnumerationForMonths │ └── README.md ├── DateWithEnum │ └── README.md └── SimulatedToggleButtonWithTest │ ├── README.md │ └── src │ ├── Switch.h │ └── Switch.cpp ├── ws02 ├── README.md ├── type_conversion_and_ub │ ├── README.md │ └── src │ │ └── type_conversion_and_ub.cpp ├── lecture_examples │ ├── README.md │ └── lecture_examples.cpp ├── tolower_chars │ ├── tolower_chars.cpp │ └── README.md ├── charcount_for_eof_demo │ ├── charcount.cpp │ └── README.md ├── greeting │ ├── README.md │ └── greeting.cpp ├── bad_greeting │ ├── README.md │ └── greeting.cpp ├── how_old_are_you_fragile │ ├── how_old_are_you_fragile.cpp │ └── README.md ├── formatted_output │ ├── README.md │ └── formatted_output.cpp ├── how_old_are_you_robust │ ├── README.md │ └── how_old_are_you_robust.cpp ├── how_old_are_you_robust_ignoring │ ├── README.md │ └── how_old_are_you_robust_ignoring.cpp ├── bad_relational_operator_example │ ├── README.md │ └── bad_relational_operator_example.cpp └── typeinfo_for_literals │ └── README.md ├── ws12 ├── demonstrate_new_delete │ ├── newdelete.cpp │ └── README.md ├── PIMPLexample │ ├── main.cpp │ ├── WizardIngredients.h │ ├── Wizard.h │ ├── Wizard_unique_ptr.h │ └── WizardPrePimpl.h ├── biblicalfamily │ ├── Person.cpp │ ├── README.md │ ├── Person.h │ └── main.cpp ├── biblicalfamily2 │ └── README.md ├── biblicalfamily3 │ └── README.md ├── shared_ptr_demo_ostream │ └── sharedPtrDemo.cpp ├── demo_unique_ptr_transfer │ └── demo_unique_ptr_transfer.cpp ├── biblicalfamily4 │ └── README.md └── unique_ptr │ └── demouniqueptr.cpp ├── solws03 ├── chcount │ └── chcount.cpp ├── chacount │ └── chacount.cpp ├── sumi │ └── sumi.cpp ├── acount │ └── acount.cpp ├── sumd │ └── sumd.cpp ├── lcount │ └── lcount.cpp ├── wcount │ └── wcount.cpp └── multab │ └── multab.cpp ├── solws02 ├── lc-newline │ └── lc.cpp ├── charc │ └── charc.cpp ├── sumi │ └── sumi.cpp ├── sumf │ └── sumf.cpp ├── allcharc │ └── allcharc.cpp ├── lc-getline │ └── lc.cpp ├── README.md ├── averagei │ └── averagei.cpp ├── averagef │ └── averagef.cpp └── wc │ └── wc.cpp ├── ws11 ├── checkODRviolationOfstaticMember │ ├── cu1.cpp │ ├── templatewithstaticmember.h │ └── cumain.cpp ├── SackScrabble │ ├── nikolaus.cpp │ └── sackscrabble.cpp ├── SafeVector │ └── SafeVector.xml └── LimitNumberOfInstances │ └── src │ └── Test.cpp ├── solws07 ├── Field5 │ └── Field5.cpp └── README.md ├── solws05 └── README.md ├── ws10 ├── minwithtemplate │ ├── MyMax.h │ ├── MyMin.h │ └── MyMaxTest.cpp ├── minwithtemplateandoverloads │ ├── MyMax.h │ ├── MyMin.cpp │ ├── MyMin.h │ └── MyMaxTest.cpp ├── minwithtemplatesandoverlaodsanddeletedoverloads │ ├── MyMax.h │ ├── MyMin.cpp │ ├── MyMin.h │ └── MyMaxTest.cpp ├── MinWithDefaultTemplateArgument │ └── src │ │ ├── MyMax.h │ │ └── MyMin.h ├── shiftoperator │ ├── shiftoperator.xml │ └── src │ │ └── Test.cpp ├── minwithouttemplate │ ├── MyMin.h │ └── main.cpp ├── demo_variadic │ └── main.cpp ├── variadiclambda │ └── variadiclambda.xml └── variadicfunctiontemplate │ └── variadicfunctiontemplate.xml ├── ws09 ├── demofunctionwithmember │ └── demofunctionwithmember.cpp ├── functordemo │ └── functordemo.cpp ├── sortstandardfunctor │ └── sortstandardfunctor.cpp └── demomemberpointer │ └── demomemberpointer.cpp ├── README.md └── .gitignore /ws04/move_enabled/.gitignore: -------------------------------------------------------------------------------- 1 | /Release/ 2 | -------------------------------------------------------------------------------- /exws11/squares/.gitignore: -------------------------------------------------------------------------------- 1 | /squares.exe.xml 2 | -------------------------------------------------------------------------------- /solws08/anagram_multiword/.gitignore: -------------------------------------------------------------------------------- 1 | /Release/ 2 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/multiplication_table/.suppressed: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/multiplication_table/.suppressed: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /exws09/wcount/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug/ 2 | /wcount.exe.xml 3 | -------------------------------------------------------------------------------- /exws09/wordle/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug/ 2 | /wordle.exe.xml 3 | -------------------------------------------------------------------------------- /exws10/woccurrence/.gitignore: -------------------------------------------------------------------------------- 1 | /woccurrence.exe.xml 2 | -------------------------------------------------------------------------------- /exws12/indexable_set/.gitignore: -------------------------------------------------------------------------------- 1 | /indexable_set.exe.xml 2 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/Shape.cpp: -------------------------------------------------------------------------------- 1 | #include "Shape.h" 2 | -------------------------------------------------------------------------------- /solws08/anagram_multiword_opt/.gitignore: -------------------------------------------------------------------------------- 1 | /Release/ 2 | -------------------------------------------------------------------------------- /ws04/chapter_function_syntax_move_ctor/.gitignore: -------------------------------------------------------------------------------- 1 | hello.txt -------------------------------------------------------------------------------- /exws09/wfavorite/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug/ 2 | /wfavorite.exe.xml 3 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/Diamond.cpp: -------------------------------------------------------------------------------- 1 | #include "Diamond.h" 2 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/Square.cpp: -------------------------------------------------------------------------------- 1 | #include "Square.h" 2 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include "Triangle.h" 2 | -------------------------------------------------------------------------------- /solws09/wcount_solution/.gitignore: -------------------------------------------------------------------------------- 1 | /wcount_solution.exe.xml 2 | -------------------------------------------------------------------------------- /solws11/median_solution/.gitignore: -------------------------------------------------------------------------------- 1 | /median_solution.exe.xml 2 | -------------------------------------------------------------------------------- /solws11/readln_solution/.gitignore: -------------------------------------------------------------------------------- 1 | /readln_solution.exe.xml 2 | -------------------------------------------------------------------------------- /ws08/ex_time_container_performance/.gitignore: -------------------------------------------------------------------------------- 1 | /Release/ 2 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/.gitignore: -------------------------------------------------------------------------------- 1 | BoundedQueue.h 2 | -------------------------------------------------------------------------------- /exws09/algorithm_trivia/.gitignore: -------------------------------------------------------------------------------- 1 | /algorithm_trivia.exe.xml 2 | -------------------------------------------------------------------------------- /exws09/wdiffcount/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug/ 2 | /wdiffcount.exe.xml 3 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/Rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include "Rectangle.h" 2 | -------------------------------------------------------------------------------- /solws10/squares_solution/.gitignore: -------------------------------------------------------------------------------- 1 | /squares_solution.exe.xml 2 | -------------------------------------------------------------------------------- /solws10/wseventh_solution/.gitignore: -------------------------------------------------------------------------------- 1 | /wseventh_solution.exe.xml 2 | -------------------------------------------------------------------------------- /ws04/chapter_function_syntax_test/hello.txt: -------------------------------------------------------------------------------- 1 | hello 2 | hello 3 | 4 | -------------------------------------------------------------------------------- /ws05/DateTest/README.md: -------------------------------------------------------------------------------- 1 | Tests for the Date library initial version. -------------------------------------------------------------------------------- /exws09/prime_numbers/.gitignore: -------------------------------------------------------------------------------- 1 | /Debug/ 2 | /prime_numbers.exe.xml 3 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/BedFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "BedFactory.h" 2 | 3 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/shoppinglist.cpp: -------------------------------------------------------------------------------- 1 | #include "shoppinglist.h" 2 | -------------------------------------------------------------------------------- /solws09/wdiffcount_solution/.gitignore: -------------------------------------------------------------------------------- 1 | /wdiffcount_solution.exe.xml 2 | -------------------------------------------------------------------------------- /solws09/wfavorite_solution/.gitignore: -------------------------------------------------------------------------------- 1 | /wfavorite_solution.exe.xml 2 | -------------------------------------------------------------------------------- /solws10/woccurrence_solution/.gitignore: -------------------------------------------------------------------------------- 1 | /woccurrence_solution.exe.xml 2 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/BoundedBufferTestat/src/.gitignore: -------------------------------------------------------------------------------- 1 | BoundedBuffer.h 2 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws09/BoundedBufferArray/src/.gitignore: -------------------------------------------------------------------------------- 1 | BoundedBuffer.h 2 | -------------------------------------------------------------------------------- /solws04/README.md: -------------------------------------------------------------------------------- 1 | These are solutions for non-Testat exercises of week 4. 2 | -------------------------------------------------------------------------------- /solws09/prime_numbers_solution/.gitignore: -------------------------------------------------------------------------------- 1 | /prime_numbers_solution.exe.xml 2 | -------------------------------------------------------------------------------- /solws11/rotate3arguments_solution/.gitignore: -------------------------------------------------------------------------------- 1 | /rotate3arguments_solution.exe.xml 2 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_sol_ws01/ex01_fraction_type/.gitignore: -------------------------------------------------------------------------------- 1 | /ex01_fraction_type.exe.xml 2 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_sol_ws01/ex01_simple_tasks/.gitignore: -------------------------------------------------------------------------------- 1 | /ex01_simple_tasks.exe.xml 2 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws09/DemoSpecialExceptionSituations/DemoSpecialExceptionSituations.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ws01/Hello/README.md: -------------------------------------------------------------------------------- 1 | This is a *C++* library project to be used by HelloTest and HelloMain. -------------------------------------------------------------------------------- /ws01/README.md: -------------------------------------------------------------------------------- 1 | This is the [Cevelop](http://cevelop.com) workspace for the first week. 2 | -------------------------------------------------------------------------------- /ws05/DateTestInitializers/README.md: -------------------------------------------------------------------------------- 1 | Test cases for the version of Date in DateInitializers. -------------------------------------------------------------------------------- /solws13/topological_sort_fast/README.md: -------------------------------------------------------------------------------- 1 | This is a faster solution to the topological_sort problem. -------------------------------------------------------------------------------- /ws01/HelloMain/README.md: -------------------------------------------------------------------------------- 1 | This is the main program to be linked to the Hello library (libHello.a). -------------------------------------------------------------------------------- /ws04/chapter_function_syntax/README.md: -------------------------------------------------------------------------------- 1 | This directory contains several examples for function syntax. -------------------------------------------------------------------------------- /ws05/DateCheckSyntax/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Date2.h" 2 | 3 | int main(){ 4 | Date{2012,8,24}; 5 | } 6 | -------------------------------------------------------------------------------- /ws05/DateTestWithBoostOperators/README.md: -------------------------------------------------------------------------------- 1 | Test cases for the version of Date in DateWithBoostOperators. -------------------------------------------------------------------------------- /ws05/MoveOnly/README.md: -------------------------------------------------------------------------------- 1 | _*Note*_: this example code is for different tests only and not to be used. 2 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws14/hello/hello.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ std::cout << "hello concepts\n";} 3 | -------------------------------------------------------------------------------- /ws03/README.md: -------------------------------------------------------------------------------- 1 | This is the [Cevelop](http://cevelop.com) workspace for the third week's lecture example code. 2 | -------------------------------------------------------------------------------- /ws05/RingModulo5InOutConversionTest/README.md: -------------------------------------------------------------------------------- 1 | A very limited set of test cases for RingModulo5InOutConversion. -------------------------------------------------------------------------------- /exws12/indexable_set/.settings/ch.hsr.ifs.cute.elevenator.prefs: -------------------------------------------------------------------------------- 1 | c_dialect=CPP_14 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /solws06/DateTestWithEnumerationForMonths/README.md: -------------------------------------------------------------------------------- 1 | Test cases for the version of Date in DateWithEnumerationForMonths. -------------------------------------------------------------------------------- /ws02/README.md: -------------------------------------------------------------------------------- 1 | This is the [Cevelop](http://cevelop.com) workspace for the second week's lecture example code. 2 | -------------------------------------------------------------------------------- /ws05/DateTestWithEnumerationForMonths/README.md: -------------------------------------------------------------------------------- 1 | Test cases for the version of Date in DateWithEnumerationForMonths. -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws01/00_01_CtylecheckerDemo/src/header.cpp: -------------------------------------------------------------------------------- 1 | //Missing include of own header 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /solws13/GardeningLibTest/src/CircleSuite.h: -------------------------------------------------------------------------------- 1 | #include "cute_suite.h" 2 | 3 | extern cute::suite make_suite_CircleSuite(); 4 | -------------------------------------------------------------------------------- /solws13/GardeningLibTest/src/SquareSuite.h: -------------------------------------------------------------------------------- 1 | #include "cute_suite.h" 2 | 3 | extern cute::suite make_suite_SquareSuite(); 4 | -------------------------------------------------------------------------------- /ws03/algorithmdemo/README.md: -------------------------------------------------------------------------------- 1 | This program demonstrates various algorithms from the C++ standard library using `std::vector`. -------------------------------------------------------------------------------- /solws13/GardeningLibTest/src/DiamondSuite.h: -------------------------------------------------------------------------------- 1 | #include "cute_suite.h" 2 | 3 | extern cute::suite make_suite_DiamondSuite(); 4 | -------------------------------------------------------------------------------- /solws13/GardeningLibTest/src/EllipseSuite.h: -------------------------------------------------------------------------------- 1 | #include "cute_suite.h" 2 | 3 | extern cute::suite make_suite_EllipseSuite(); 4 | -------------------------------------------------------------------------------- /solws13/GardeningLibTest/src/RectangleSuite.h: -------------------------------------------------------------------------------- 1 | #include "cute_suite.h" 2 | 3 | extern cute::suite make_suite_RectangleSuite(); 4 | -------------------------------------------------------------------------------- /solws13/GardeningLibTest/src/TriangleSuite.h: -------------------------------------------------------------------------------- 1 | #include "cute_suite.h" 2 | 3 | extern cute::suite make_suite_TriangleSuite(); 4 | -------------------------------------------------------------------------------- /ws04/exception_syntax/README.md: -------------------------------------------------------------------------------- 1 | This project demonstrates exception syntax. 2 | Do not use it as a good example of how to use exceptions. -------------------------------------------------------------------------------- /solws13/GardeningLibTest/src/PolymorphismSuite.h: -------------------------------------------------------------------------------- 1 | #include "cute_suite.h" 2 | 3 | extern cute::suite make_suite_PolymorphismSuite(); 4 | -------------------------------------------------------------------------------- /ws04/main_try_catch/main_try_catch.cpp: -------------------------------------------------------------------------------- 1 | int main(int argc,char const *const argv[]) 2 | try{ 3 | } 4 | catch(...){ 5 | argc++; 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/TestBoundedQueueAPI.h: -------------------------------------------------------------------------------- 1 | #include "cute_suite.h" 2 | 3 | extern cute::suite make_suite_TestBoundedQueueAPI(); 4 | -------------------------------------------------------------------------------- /ws01/Hello/sayhello.cpp: -------------------------------------------------------------------------------- 1 | #include "sayhello.h" 2 | 3 | #include 4 | void sayHello(std::ostream& out) { 5 | out << "Hello, world!\n"; 6 | } 7 | -------------------------------------------------------------------------------- /ws01/HelloMain/hellomain.cpp: -------------------------------------------------------------------------------- 1 | #include "Hello.h" 2 | #include 3 | 4 | int main(){ 5 | Hello h { }; 6 | h.sayHello(std::cout); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /ws01/Hello/Hello.cpp: -------------------------------------------------------------------------------- 1 | #include "Hello.h" 2 | #include 3 | void Hello::sayHello(std::ostream& out) const { 4 | out << "Hello, world!\n"; 5 | } 6 | -------------------------------------------------------------------------------- /ws01/HelloTest/README.md: -------------------------------------------------------------------------------- 1 | This is the CUTE test case for testing our Hello library. 2 | 3 | It is incomplete, because it is not testing the Hello class yet. -------------------------------------------------------------------------------- /ws04/namespacesyntax/README.md: -------------------------------------------------------------------------------- 1 | This bad code example just demonstrates the effect of namespaces. 2 | 3 | Do not use it as an example for your own code. 4 | -------------------------------------------------------------------------------- /ws05/DateWithBoostOperators/README.md: -------------------------------------------------------------------------------- 1 | Implementation of the Date class that uses Boost.operators library 2 | for simpler implementation of relational operators. -------------------------------------------------------------------------------- /ws02/type_conversion_and_ub/README.md: -------------------------------------------------------------------------------- 1 | This program shows integer division effect and 2 | has a part that will be undefined behavior if uncommented, compiled and run. -------------------------------------------------------------------------------- /ws04/exception_testing/src/squareroot.h: -------------------------------------------------------------------------------- 1 | #ifndef SQUAREROOT_H_ 2 | #define SQUAREROOT_H_ 3 | 4 | double square_root(double x); 5 | 6 | #endif /* SQUAREROOT_H_ */ 7 | -------------------------------------------------------------------------------- /ws12/demonstrate_new_delete/newdelete.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | auto ptr=new int{5}; 5 | std::cout << *ptr << '\n'; 6 | delete ptr; 7 | } 8 | -------------------------------------------------------------------------------- /ws01/Hello/sayhello.h: -------------------------------------------------------------------------------- 1 | #ifndef SAYHELLO_H_ 2 | #define SAYHELLO_H_ 3 | 4 | #include 5 | 6 | void sayHello(std::ostream& out); 7 | 8 | #endif /* SAYHELLO_H_ */ 9 | -------------------------------------------------------------------------------- /ws02/lecture_examples/README.md: -------------------------------------------------------------------------------- 1 | This is a project to be extended during the lecture for ad-hoc examples. 2 | 3 | It currently shows how to use the string literal suffix s. -------------------------------------------------------------------------------- /solws09/wfavorite_solution/test_resources/chapter_6.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterSommerlad/CPlusPlusLecture/HEAD/solws09/wfavorite_solution/test_resources/chapter_6.txt -------------------------------------------------------------------------------- /solws10/wseventh_solution/test_resources/chapter_6.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterSommerlad/CPlusPlusLecture/HEAD/solws10/wseventh_solution/test_resources/chapter_6.txt -------------------------------------------------------------------------------- /ws05/DateWithEnumerationForMonths/README.md: -------------------------------------------------------------------------------- 1 | Version of the Date class that uses an enum type for representing months instead of int. 2 | 3 | Extension to DateWithBoostOperators. -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/ratio_demo/src/.vscode/.browse.VC.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterSommerlad/CPlusPlusLecture/HEAD/CppAdvanced/cpla_ws11/ratio_demo/src/.vscode/.browse.VC.db -------------------------------------------------------------------------------- /exws09/wcount/src/wcount.h: -------------------------------------------------------------------------------- 1 | #ifndef WCOUNT_H_ 2 | #define WCOUNT_H_ 3 | 4 | #include 5 | 6 | unsigned wcount(std::istream & in); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /exws11/readln/src/readln.h: -------------------------------------------------------------------------------- 1 | #ifndef READLN_H_ 2 | #define READLN_H_ 3 | 4 | //TODO Add your definition of the readln function template here 5 | 6 | 7 | #endif /* READLN_H_ */ 8 | -------------------------------------------------------------------------------- /ws04/namespacesyntax/demoanonymous.cpp: -------------------------------------------------------------------------------- 1 | void caller(){ 2 | void print(); // declare print 3 | print(); 4 | void doit(); // declare doit 5 | //doit(); // linker error 6 | } 7 | -------------------------------------------------------------------------------- /ws05/DateInitializers/README.md: -------------------------------------------------------------------------------- 1 | This evolution step for the Date class demonstrates the use of 2 | "non-static-data-member-initializers" NSDMI for constructing a default Date value. -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws14/lessthan/lessthan.h: -------------------------------------------------------------------------------- 1 | template 2 | concept bool LessThanComparable() { 3 | return requires(LTC a, LTC b) { 4 | { a < b } -> bool; 5 | }; 6 | } 7 | -------------------------------------------------------------------------------- /exws11/median/src/median.h: -------------------------------------------------------------------------------- 1 | #ifndef MEDIAN_H_ 2 | #define MEDIAN_H_ 3 | 4 | 5 | //TODO Add your definition of the median function template here 6 | 7 | 8 | #endif /* MEDIAN_H_ */ 9 | -------------------------------------------------------------------------------- /exws12/DynArray/src/dynArray.h: -------------------------------------------------------------------------------- 1 | #ifndef DYNARRAY_H_ 2 | #define DYNARRAY_H_ 3 | 4 | 5 | //TODO: Add the implementation of your dynArray here 6 | 7 | 8 | #endif /* DYNARRAY_H_ */ 9 | -------------------------------------------------------------------------------- /solws06/DateWithEnum/README.md: -------------------------------------------------------------------------------- 1 | Extended Date class with an enum for the day of week and a computation of such. 2 | 3 | Demonstrates overloads of the constructor and constructor delegation. -------------------------------------------------------------------------------- /ws03/tolower/src/tolower.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | char c{}; 5 | while(std::cin.get(c)){ 6 | std::cout.put(std::tolower(c)); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ws08/ex_time_container_performance/timer.h: -------------------------------------------------------------------------------- 1 | #ifndef TIMER_H_ 2 | #define TIMER_H_ 3 | #include 4 | std::chrono::microseconds time_func(void (f)()); 5 | #endif /* TIMER_H_ */ 6 | -------------------------------------------------------------------------------- /solws09/wcount_solution/src/wcount.h: -------------------------------------------------------------------------------- 1 | #ifndef WCOUNT_H_ 2 | #define WCOUNT_H_ 3 | 4 | #include 5 | 6 | unsigned wcount(std::istream & in); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /ws05/README.md: -------------------------------------------------------------------------------- 1 | This workspace contains projects for demonstrating defining types and operator overloading. 2 | 3 | It will be used in weeks 5 and 6, and even may be week 7 of HS2015. 4 | 5 | -------------------------------------------------------------------------------- /exws11/squares/src/squares.h: -------------------------------------------------------------------------------- 1 | #ifndef SQUARES_H_ 2 | #define SQUARES_H_ 3 | 4 | #include 5 | 6 | std::vector fill_with_squares(); 7 | 8 | 9 | #endif /* SQUARES_H_ */ 10 | -------------------------------------------------------------------------------- /solws03/chcount/chcount.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | using in=std::istream_iterator; 5 | std::cout << distance(in{std::cin},in{}); 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /solws08/anagram/README.md: -------------------------------------------------------------------------------- 1 | Simple solution for anagrams 2 | 3 | The answer for the real words in tha anagrams for the word "listen" is 4 | 5 | * enlist 6 | * listen 7 | * silent 8 | * tinsel 9 | -------------------------------------------------------------------------------- /ws02/tolower_chars/tolower_chars.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | char c{}; 5 | while(std::cin.get(c)){ 6 | std::cout.put(std::tolower(c)); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /ws05/Date/Date0.h: -------------------------------------------------------------------------------- 1 | #ifndef DATE_H_ 2 | #define DATE_H_ 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | struct Date{ 11 | int year, month, day; 12 | }; 13 | 14 | 15 | #endif /* DATE_H_ */ 16 | -------------------------------------------------------------------------------- /exws10/wseventh/src/wseventh.h: -------------------------------------------------------------------------------- 1 | #ifndef WSEVENTH_H_ 2 | #define WSEVENTH_H_ 3 | 4 | #include 5 | 6 | void wseventh(std::istream & in, std::ostream & out); 7 | 8 | #endif /* SWSEVENTH_H_ */ 9 | -------------------------------------------------------------------------------- /solws02/lc-newline/lc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | unsigned count{}; 4 | while(std::cin) 5 | if (std::cin.get()=='\n') 6 | ++count; 7 | std::cout << count << " lines\n"; 8 | } 9 | -------------------------------------------------------------------------------- /ws01/Hello/Hello.h: -------------------------------------------------------------------------------- 1 | #ifndef HELLO_H_ 2 | #define HELLO_H_ 3 | 4 | #include 5 | 6 | struct Hello { 7 | void sayHello(std::ostream& out) const; 8 | }; 9 | #endif /* HELLO_H_ */ 10 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/fibo_sequence/fibo_sequence.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /exws09/README.md: -------------------------------------------------------------------------------- 1 | This directory contains the scaffolding for the exercises in week 9 2 | 3 | Clone the directory and start to work on the exercises given at 4 | https://wiki.ifs.hsr.ch/CPlusPlus/ExW9 5 | -------------------------------------------------------------------------------- /exws09/wcount/src/wcount.cpp: -------------------------------------------------------------------------------- 1 | #include "wcount.h" 2 | #include 3 | 4 | 5 | unsigned wcount(std::istream& in) { 6 | //TODO: Implement your wcount functionality here 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /exws12/indexable_set/src/indexableSet.h: -------------------------------------------------------------------------------- 1 | #ifndef INDEXABLESET_H_ 2 | #define INDEXABLESET_H_ 3 | 4 | //TODO: Add the implementation of your indexableSet here 5 | 6 | 7 | #endif /* INDEXABLESET_H_ */ 8 | -------------------------------------------------------------------------------- /solws03/chacount/chacount.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | using in=std::istreambuf_iterator; 5 | std::cout << std::distance(in{std::cin},in{}); 6 | } 7 | 8 | 9 | -------------------------------------------------------------------------------- /ws02/charcount_for_eof_demo/charcount.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | size_t count{0}; 4 | char c{}; 5 | while (std::cin >> c) ++count; 6 | std::cout << count << "\n"; 7 | } 8 | -------------------------------------------------------------------------------- /ws03/vectordemo/README.md: -------------------------------------------------------------------------------- 1 | *vectordemo.cpp* shows different means to iterate over a C++ standard container. However, you should always prefer a standard algorith instead, if one is available for your problem. -------------------------------------------------------------------------------- /ws11/checkODRviolationOfstaticMember/cu1.cpp: -------------------------------------------------------------------------------- 1 | #include "templatewithstaticmember.h" 2 | 3 | int foo(){ 4 | using dummytype=staticmember; 5 | dummytype::dummy=42; 6 | return dummytype::dummy; 7 | } 8 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws12/HairpollClient/README.md: -------------------------------------------------------------------------------- 1 | example code taken from https://github.com/CppCon/CppCon2014/tree/master/Presentations/Hourglass%20Interfaces%20for%20C%2B%2B%20APIs/code 2 | 3 | (c) Stefanus du Toit -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws12/HairpollLib/README.md: -------------------------------------------------------------------------------- 1 | example code taken from https://github.com/CppCon/CppCon2014/tree/master/Presentations/Hourglass%20Interfaces%20for%20C%2B%2B%20APIs/code 2 | 3 | (c) Stefanus du Toit -------------------------------------------------------------------------------- /solws10/wseventh_solution/src/wseventh.h: -------------------------------------------------------------------------------- 1 | #ifndef WSEVENTH_H_ 2 | #define WSEVENTH_H_ 3 | 4 | #include 5 | 6 | void wseventh(std::istream & in, std::ostream & out); 7 | 8 | #endif /* SWSEVENTH_H_ */ 9 | -------------------------------------------------------------------------------- /ws04/chapter_function_syntax/overload.h: -------------------------------------------------------------------------------- 1 | #ifndef OVERLOAD_H_ 2 | #define OVERLOAD_H_ 3 | namespace overload{ 4 | void incr(int& var); 5 | void incr(int& var, unsigned delta); 6 | } 7 | #endif /* OVERLOAD_H_ */ 8 | -------------------------------------------------------------------------------- /ws05/Date/README.md: -------------------------------------------------------------------------------- 1 | The different files show the first steps of evolution of the Date class. 2 | 3 | For further versions see DateIntializers, DateWithBoostOperators and DateWithEnumerationForMonths. 4 | 5 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/LiteralTypesAndUDL/LiteralTypesAndUDL.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /exws09/wordle/src/wordle.h: -------------------------------------------------------------------------------- 1 | #ifndef WORDLE_H_ 2 | #define WORDLE_H_ 3 | 4 | #include 5 | 6 | void wordle(std::istream & in, std::ostream & out); 7 | 8 | 9 | #endif /* WORDLE_H_ */ 10 | -------------------------------------------------------------------------------- /solws07/Field5/Field5.cpp: -------------------------------------------------------------------------------- 1 | #include "Field5.h" 2 | 3 | #include 4 | 5 | std::ostream& operator <<(std::ostream& out, const Field5& r) { 6 | out << "Field5{" << r.value() << '}'; 7 | return out; 8 | } 9 | -------------------------------------------------------------------------------- /solws10/squares_solution/src/squares.h: -------------------------------------------------------------------------------- 1 | #ifndef SQUARES_H_ 2 | #define SQUARES_H_ 3 | 4 | #include 5 | 6 | std::vector fill_with_squares(); 7 | 8 | 9 | #endif /* SQUARES_H_ */ 10 | -------------------------------------------------------------------------------- /ws04/chapter_function_syntax/overload.cpp: -------------------------------------------------------------------------------- 1 | #include "overload.h" 2 | namespace overload{ 3 | void incr(int& var, unsigned delta) { 4 | var += delta; 5 | } 6 | void incr(int& var) { 7 | ++var; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /ws05/RingModulo5Constexpr/Ring5.cpp: -------------------------------------------------------------------------------- 1 | #include "Ring5.h" 2 | #include 3 | 4 | std::ostream& operator <<(std::ostream& out, const Ring5& r) { 5 | out << "Ring5{" << r.value() << '}'; 6 | return out; 7 | } 8 | -------------------------------------------------------------------------------- /ws12/PIMPLexample/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Wizard.h" 2 | 3 | #include 4 | int main(){ 5 | Pimpl::Wizard harry{"Potter"}; 6 | std::cout << harry.doMagic("Expecto Patronus!"); 7 | } 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /exws09/wdiffcount/src/wdiffcount.h: -------------------------------------------------------------------------------- 1 | #ifndef WDIFFCOUNT_H_ 2 | #define WDIFFCOUNT_H_ 3 | 4 | #include 5 | 6 | unsigned wdiffcount(std::istream & in); 7 | 8 | 9 | #endif /* WDIFFCOUNT_H_ */ 10 | -------------------------------------------------------------------------------- /exws09/wordle/src/wordle.cpp: -------------------------------------------------------------------------------- 1 | #include "wordle.h" 2 | #include 3 | #include 4 | 5 | void wordle(std::istream & in, std::ostream & out) { 6 | //TODO: Implement your wordle functionality here 7 | } -------------------------------------------------------------------------------- /exws10/woccurrence/src/woccurrence.h: -------------------------------------------------------------------------------- 1 | #ifndef WOCCURRENCE_H_ 2 | #define WOCCURRENCE_H_ 3 | 4 | #include 5 | 6 | void woccurrence(std::istream & in, std::ostream & out); 7 | 8 | #endif /* WOCCURENCE_H_ */ 9 | -------------------------------------------------------------------------------- /solws04/wlist_caseless/README.md: -------------------------------------------------------------------------------- 1 | This is a solution using vector and algorithms instead of using a set. 2 | 3 | For the case-less comparing a corresponding comparison predicate 4 | is implemented for less and equal. 5 | -------------------------------------------------------------------------------- /ws01/helloworld/README.md: -------------------------------------------------------------------------------- 1 | This is the Eclipse-CDT default-generated "Hello World" program. 2 | 3 | It contains bad code and I encourage you not to follow its example. 4 | 5 | Its only means here is to show a bad example. -------------------------------------------------------------------------------- /ws02/lecture_examples/lecture_examples.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(){ 4 | using namespace std::string_literals; 5 | auto s="hello"s; 6 | std::cout << s; 7 | } 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ws04/exception_syntax/noexcept.cpp: -------------------------------------------------------------------------------- 1 | int minimum(int a, int b, int c) noexcept { 2 | return ab?(a>c?a:c):(b>c?b:c); 7 | } 8 | -------------------------------------------------------------------------------- /exws09/wdiffcount/src/wdiffcount.cpp: -------------------------------------------------------------------------------- 1 | #include "wdiffcount.h" 2 | 3 | #include 4 | 5 | unsigned wdiffcount(std::istream& in) { 6 | //TODO: Implement your wdiffcount functionality here 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /solws02/charc/charc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | unsigned count{}; 4 | char c{}; 5 | while(std::cin>>c)++count; 6 | std::cout << count << " non-whitespace characters\n"; 7 | } 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /solws02/sumi/sumi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int sum{}; 4 | while(std::cin){ 5 | int val{}; 6 | std::cin >> val; 7 | sum += val; 8 | } 9 | std::cout << sum << " sum of integers\n"; 10 | } 11 | -------------------------------------------------------------------------------- /solws03/sumi/sumi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(){ 5 | using in=std::istream_iterator; 6 | std::cout << accumulate(in{std::cin},in{},0); 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /solws05/README.md: -------------------------------------------------------------------------------- 1 | source code for experiment with Tracer class. 2 | 3 | This code shows when objects are created, copied and detroyed. 4 | 5 | Usually you won't write your own destructors or copy constructors. 6 | 7 | 8 | -------------------------------------------------------------------------------- /ws04/exception_syntax/standardexcept.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | double square_root(double x){ 4 | if (x<0) 5 | throw std::invalid_argument{"square_root imaginary"}; 6 | return std::sqrt(x); 7 | } 8 | -------------------------------------------------------------------------------- /ws04/exception_testing/README.md: -------------------------------------------------------------------------------- 1 | This example shows how to test for exceptions. 2 | 3 | If you define a narrow contract for your functions, 4 | and check for it, 5 | you must also provide test cases for such defined behavior. -------------------------------------------------------------------------------- /ws05/RingModulo5InOutConversion/Ring5.cpp: -------------------------------------------------------------------------------- 1 | #include "Ring5.h" 2 | #include 3 | 4 | std::ostream& operator <<(std::ostream& out, const Ring5& r) { 5 | out << "Ring5{" << r.value() << '}'; 6 | return out; 7 | } 8 | -------------------------------------------------------------------------------- /ws05/RingModulo5MixedArithmetic/Ring5.cpp: -------------------------------------------------------------------------------- 1 | #include "Ring5.h" 2 | #include 3 | 4 | std::ostream& operator <<(std::ostream& out, const Ring5& r) { 5 | out << "Ring5{" << r.value() << '}'; 6 | return out; 7 | } 8 | -------------------------------------------------------------------------------- /ws10/minwithtemplate/MyMax.h: -------------------------------------------------------------------------------- 1 | #ifndef MYMAX_H_ 2 | #define MYMAX_H_ 3 | namespace MyMax{ 4 | template 5 | T max(T a, T b){ 6 | return a < b ? b : a; 7 | } 8 | 9 | } 10 | 11 | #endif /* MYMAX_H_ */ 12 | -------------------------------------------------------------------------------- /exws09/wfavorite/src/wfavorite.h: -------------------------------------------------------------------------------- 1 | #ifndef WFAVORITE_H_ 2 | #define WFAVORITE_H_ 3 | 4 | #include 5 | 6 | void wfavorite(std::istream & in, std::ostream & out); 7 | 8 | 9 | #endif /* WFAVORITE_H_ */ 10 | -------------------------------------------------------------------------------- /solws02/sumf/sumf.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | double sum{}; 4 | while(std::cin){ 5 | double val{}; 6 | std::cin >> val; 7 | sum += val; 8 | } 9 | std::cout << sum << " sum of doubles\n"; 10 | } 11 | -------------------------------------------------------------------------------- /solws03/acount/acount.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(){ 5 | using in=std::istream_iterator; 6 | std::cout << count(in{std::cin},in{},'a'); 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /solws03/sumd/sumd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(){ 5 | using in=std::istream_iterator; 6 | std::cout << accumulate(in{std::cin},in{},0.0); 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /solws09/wdiffcount_solution/src/wdiffcount.h: -------------------------------------------------------------------------------- 1 | #ifndef WDIFFCOUNT_H_ 2 | #define WDIFFCOUNT_H_ 3 | 4 | #include 5 | 6 | unsigned wdiffcount(std::istream & in); 7 | 8 | 9 | #endif /* WDIFFCOUNT_H_ */ 10 | -------------------------------------------------------------------------------- /solws10/woccurrence_solution/src/woccurrence.h: -------------------------------------------------------------------------------- 1 | #ifndef WOCCURRENCE_H_ 2 | #define WOCCURRENCE_H_ 3 | 4 | #include 5 | 6 | void woccurrence(std::istream & in, std::ostream & out); 7 | 8 | #endif /* WOCCURENCE_H_ */ 9 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/Cpp14CompileTimeComputation/Cpp14CompileTimeComputation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /solws03/lcount/lcount.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(){ 5 | using in=std::istreambuf_iterator; 6 | std::cout << count(in{std::cin},in{},'\n'); 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /solws03/wcount/wcount.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(){ 5 | using in=std::istream_iterator; 6 | std::cout << distance(in{std::cin},in{}); 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /solws13/topological_sort_main/README.md: -------------------------------------------------------------------------------- 1 | This project contains a simple main program for the topological sort problem. 2 | 3 | It demonstrates the use of program arguments and contains the test data from the exercise as a "canned" input. -------------------------------------------------------------------------------- /ws02/type_conversion_and_ub/src/type_conversion_and_ub.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | double x = 45/8; 5 | std::cout << "45/8=" < 5 | T max(T a, T b){ 6 | return a < b ? b : a; 7 | } 8 | 9 | } 10 | 11 | #endif /* MYMAX_H_ */ 12 | -------------------------------------------------------------------------------- /exws09/algorithm_trivia/src/set_algorithms.h: -------------------------------------------------------------------------------- 1 | #ifndef SET_ALGORITHMS_H_ 2 | #define SET_ALGORITHMS_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_set_algorithms(); 7 | 8 | #endif /* SET_ALGORITHMS_H_ */ 9 | -------------------------------------------------------------------------------- /exws09/wfavorite/src/wfavorite.cpp: -------------------------------------------------------------------------------- 1 | #include "wfavorite.h" 2 | 3 | #include 4 | #include 5 | 6 | void wfavorite(std::istream & in, std::ostream & out) { 7 | //TODO: Implement your wfavorite functionality here 8 | } -------------------------------------------------------------------------------- /solws09/wfavorite_solution/src/wfavorite.h: -------------------------------------------------------------------------------- 1 | #ifndef WFAVORITE_H_ 2 | #define WFAVORITE_H_ 3 | 4 | #include 5 | 6 | 7 | void wfavorite(std::istream & in, std::ostream & out); 8 | 9 | 10 | #endif /* WFAVORITE_H_ */ 11 | -------------------------------------------------------------------------------- /ws02/greeting/README.md: -------------------------------------------------------------------------------- 1 | A very simple example showing `std::string` input and output and 2 | how to pass stream objects by reference to functions to have 3 | side effects on them. Actually reading input or writing output 4 | are side effects! -------------------------------------------------------------------------------- /ws04/chapter_function_syntax/defaultargument.h: -------------------------------------------------------------------------------- 1 | #ifndef DEFAULTARGUMENT_H_ 2 | #define DEFAULTARGUMENT_H_ 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | void incr(int &var,unsigned delta=1); 11 | 12 | #endif /* DEFAULTARGUMENT_H_ */ 13 | -------------------------------------------------------------------------------- /ws05/RingModulo5ConstexprTest/README.md: -------------------------------------------------------------------------------- 1 | Limited set of test cases for the constexpr version of Ring5. 2 | 3 | More static_assert compile-time tests are needed. 4 | 5 | Add them as an exercise as well as the missing arithmetic operators. -------------------------------------------------------------------------------- /ws10/minwithtemplate/MyMin.h: -------------------------------------------------------------------------------- 1 | #ifndef MYMIN_H_ 2 | #define MYMIN_H_ 3 | namespace MyMin{ 4 | template 5 | T const& min(T const& a, T const& b){ 6 | return (a < b)? a : b ; 7 | } 8 | } 9 | #endif /*MYMIN_H_*/ 10 | -------------------------------------------------------------------------------- /ws10/minwithtemplateandoverloads/MyMin.cpp: -------------------------------------------------------------------------------- 1 | #include "MyMin.h" 2 | #include 3 | namespace MyMin { 4 | 5 | const char* min(const char* a, const char* b) { 6 | return std::string(a) 3 | 4 | bool is_prime(unsigned long long n) { 5 | return true; 6 | } 7 | 8 | void primes(std::ostream & out, unsigned long long limit) { 9 | 10 | } -------------------------------------------------------------------------------- /exws11/rotate3arguments/src/rotate3arguments.h: -------------------------------------------------------------------------------- 1 | #ifndef ROTATE3ARGUMENTS_H_ 2 | #define ROTATE3ARGUMENTS_H_ 3 | 4 | 5 | //TODO Add your definition of the rotate3arguments function template here 6 | 7 | 8 | #endif /* ROTATE3ARGUMENTS_H_ */ 9 | -------------------------------------------------------------------------------- /solws02/allcharc/allcharc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | unsigned count{}; 4 | while(std::cin.get()!=std::istream::traits_type::eof() ) 5 | ++count; 6 | std::cout << count << " characters\n"; 7 | } 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /solws07/README.md: -------------------------------------------------------------------------------- 1 | Implementation of Field5 exercise. 2 | 3 | Equality operator is needed for test cases. 4 | 5 | Other relational operators could be useful, if Field5 values should be put into an associative container such as std::multiset. 6 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/Cpp03compileTimeComputation/Cpp03compileTimeComputation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /exws10/woccurrence/src/woccurrence.cpp: -------------------------------------------------------------------------------- 1 | #include "woccurrence.h" 2 | 3 | #include 4 | #include 5 | 6 | void woccurrence(std::istream & in, std::ostream & out) { 7 | //TODO: Implement your woccurrence functionality here 8 | } -------------------------------------------------------------------------------- /ws10/minwithtemplatesandoverlaodsanddeletedoverloads/MyMax.h: -------------------------------------------------------------------------------- 1 | #ifndef MYMAX_H_ 2 | #define MYMAX_H_ 3 | namespace MyMax{ 4 | template 5 | T max(T a, T b){ 6 | return a < b ? b : a; 7 | } 8 | 9 | } 10 | 11 | #endif /* MYMAX_H_ */ 12 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws12/Wizard/WizardIngredients.h: -------------------------------------------------------------------------------- 1 | #ifndef WIZARDINGREDIENTS_H_ 2 | #define WIZARDINGREDIENTS_H_ 3 | 4 | using Potion=std::string; 5 | struct MagicWand{}; 6 | using Spell=std::string; 7 | 8 | 9 | #endif /* WIZARDINGREDIENTS_H_ */ 10 | -------------------------------------------------------------------------------- /exws09/algorithm_trivia/src/min_max_algorithms.h: -------------------------------------------------------------------------------- 1 | #ifndef MIN_MAX_ALGORITHMS_H_ 2 | #define MIN_MAX_ALGORITHMS_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_min_max_algorithms(); 7 | 8 | #endif /* MIN_MAX_ALGORITHMS_H_ */ 9 | -------------------------------------------------------------------------------- /exws09/algorithm_trivia/src/numeric_algorithms.h: -------------------------------------------------------------------------------- 1 | #ifndef NUMERIC_ALGORITHMS_H_ 2 | #define NUMERIC_ALGORITHMS_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_numeric_algorithms(); 7 | 8 | #endif /* NUMERIC_ALGORITHMS_H_ */ 9 | -------------------------------------------------------------------------------- /solws13/topological_sort_fast/semester.h: -------------------------------------------------------------------------------- 1 | #ifndef SEMESTER_H_ 2 | #define SEMESTER_H_ 3 | 4 | #include 5 | #include 6 | 7 | void print_semester(std::string filename, std::ostream& out); 8 | 9 | #endif /* SEMESTER_H_ */ 10 | -------------------------------------------------------------------------------- /ws02/bad_greeting/README.md: -------------------------------------------------------------------------------- 1 | **Never** program this way, by calling a side-effect-full function/operation 2 | on the same variable twice in a single expression. 3 | 4 | This project is provided only for completeness of the code examples from the 5 | lecture. -------------------------------------------------------------------------------- /ws04/exception_testing/src/squareroot.cpp: -------------------------------------------------------------------------------- 1 | #include "squareroot.h" 2 | #include 3 | #include 4 | double square_root(double x) { 5 | if (x < 0) 6 | throw std::invalid_argument{"square_root imaginary"}; 7 | return std::sqrt(x); 8 | } 9 | -------------------------------------------------------------------------------- /ws10/minwithtemplatesandoverlaodsanddeletedoverloads/MyMin.cpp: -------------------------------------------------------------------------------- 1 | #include "MyMin.h" 2 | #include 3 | namespace MyMin { 4 | 5 | const char* min(const char* a, const char* b) { 6 | return std::string(a) 2 | #include 3 | int main(){ 4 | unsigned count{}; 5 | std::string s{}; 6 | while(getline(std::cin,s))++count; 7 | std::cout << count << " lines\n"; 8 | } 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /ws04/chapter_function_syntax/defaultargument.cpp: -------------------------------------------------------------------------------- 1 | #include "defaultargument.h" 2 | void incr(int &var,unsigned delta){ 3 | var += delta; 4 | } 5 | 6 | 7 | 8 | 9 | void use_incr(){ 10 | int i{42}; 11 | incr(i); // 43 12 | incr(i,2); // 45 13 | } 14 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws12/WizardPimpl/src/WizardIngredients.h: -------------------------------------------------------------------------------- 1 | #ifndef WIZARDINGREDIENTS_H_ 2 | #define WIZARDINGREDIENTS_H_ 3 | 4 | using Potion=std::string; 5 | struct MagicWand{}; 6 | using Spell=std::string; 7 | 8 | 9 | #endif /* WIZARDINGREDIENTS_H_ */ 10 | -------------------------------------------------------------------------------- /exws09/algorithm_trivia/src/partition_algorithms.h: -------------------------------------------------------------------------------- 1 | #ifndef PARTITION_ALGORITHMS_H_ 2 | #define PARTITION_ALGORITHMS_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_partition_algorithms(); 7 | 8 | #endif /* PARTITION_ALGORITHMS_H_ */ 9 | -------------------------------------------------------------------------------- /exws11/squares/src/squares.cpp: -------------------------------------------------------------------------------- 1 | #include "squares.h" 2 | 3 | #include 4 | 5 | std::vector fill_with_squares() { 6 | std::vector squares(10, 1); 7 | //TODO: Calculate "squares" using standard functors 8 | 9 | return squares; 10 | } 11 | -------------------------------------------------------------------------------- /solws04/FunctionValueTable/funcval.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCVAL_H_ 2 | #define FUNCVAL_H_ 3 | #include 4 | void printFunctionTable(std::ostream& out, 5 | double b, double e, int steps, 6 | double func(double)); 7 | 8 | #endif /* FUNCVAL_H_ */ 9 | -------------------------------------------------------------------------------- /ws04/chapter_function_syntax/hello.txt: -------------------------------------------------------------------------------- 1 | hello, world! 2 | hello, world! 3 | hello, world! 4 | hello, world! 5 | hello, world! 6 | hello, world! 7 | hello, world! 8 | hello, world! 9 | hello, world! 10 | hello, world! 11 | hello, world! 12 | hello, world! 13 | 14 | -------------------------------------------------------------------------------- /ws08/demolambda/main.cpp: -------------------------------------------------------------------------------- 1 | int main(){ 2 | int j{}; 3 | int k{}; 4 | auto l=[&j,k](int i){ j = i; return i*i;}; 5 | l(3); 6 | 7 | auto odd=[](int i){ return i%2;}; 8 | auto divides=[](int i,int j){ return i%j==0;}; 9 | } 10 | 11 | 12 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws13/DemoOptional/DemoOptional.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /exws09/prime_numbers/src/primes.h: -------------------------------------------------------------------------------- 1 | #ifndef PRIMES_H_ 2 | #define PRIMES_H_ 3 | 4 | #include 5 | 6 | bool is_prime(unsigned long long n); 7 | 8 | void primes(std::ostream & out, unsigned long long limit); 9 | 10 | 11 | #endif /* PRIMES_H_ */ 12 | -------------------------------------------------------------------------------- /ws02/how_old_are_you_fragile/how_old_are_you_fragile.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | std::cout << "Enter your age: " << std::flush; 4 | int age{-1}; 5 | std::cin >> age; 6 | std::cout << "\nYou are " << age 7 | << " years old\n"; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws04/04_06_initializer_list_as_template_argument/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template 4 | void f(T param) { 5 | 6 | } 7 | 8 | 9 | int main(int argc, char **argv) { 10 | f({23, 24}); // compile error! 11 | } 12 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/bounded_queue_content_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_CONTENT_SUITE_H_ 2 | #define BOUNDED_QUEUE_CONTENT_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_content_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/BoundedQueue/src/bounded_queue_content_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_CONTENT_SUITE_H_ 2 | #define BOUNDED_QUEUE_CONTENT_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_content_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /solws13/topological_sort_fast/semester_topological.h: -------------------------------------------------------------------------------- 1 | #ifndef SEMESTER_TOPOLOGICAL_H_ 2 | #define SEMESTER_TOPOLOGICAL_H_ 3 | 4 | #include 5 | void print_semester_topological(std::istream &input, std::ostream& out); 6 | 7 | #endif /* SEMESTER_TOPOLOGICAL_H_ */ 8 | -------------------------------------------------------------------------------- /ws02/how_old_are_you_fragile/README.md: -------------------------------------------------------------------------------- 1 | This program shows very simple integer input from a `std::istream`. 2 | 3 | **Note:** This is error prone and not robust. 4 | Wrong input will cause the std::istream to enter _fail_ mode in which it 5 | stays until `clear()` is called on it. -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws08/08_02_traits_is_class/src/08_02_traits_is_class.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | struct S; 6 | int main() { 7 | using namespace std; 8 | cout << boolalpha << is_class_v << is_class_v; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/TestBoundedQueueAPI.cpp: -------------------------------------------------------------------------------- 1 | #include "TestBoundedQueueAPI.h" 2 | #include "BoundedQueue.h" 3 | #include "cute.h" 4 | 5 | 6 | 7 | cute::suite make_suite_TestBoundedQueueAPI(){ 8 | cute::suite s; 9 | return s; 10 | } 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/bounded_queue_semantic_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_SEMANTIC_SUITE_H_ 2 | #define BOUNDED_QUEUE_SEMANTIC_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_semantic_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/BoundedQueue/src/bounded_queue_semantic_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_SEMANTIC_SUITE_H_ 2 | #define BOUNDED_QUEUE_SEMANTIC_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_semantic_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /solws09/prime_numbers_solution/src/primes.h: -------------------------------------------------------------------------------- 1 | #ifndef PRIMES_H_ 2 | #define PRIMES_H_ 3 | 4 | #include 5 | 6 | bool is_prime(unsigned long long n); 7 | 8 | void primes(std::ostream & out, unsigned long long limit); 9 | 10 | 11 | #endif /* PRIMES_H_ */ 12 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_sol_ws02/SolEx02_01_ExtensionsForDynArray/Ex02_0x_DeductionForIndexableSet.exe.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/BoundedBufferTestat/src/bounded_buffer_content_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_CONTENT_SUITE_H_ 2 | #define BOUNDED_BUFFER_CONTENT_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_content_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws09/BoundedBufferArray/src/bounded_buffer_content_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_CONTENT_SUITE_H_ 2 | #define BOUNDED_BUFFER_CONTENT_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_content_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/bounded_queue_signatures_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_SIGNATURES_SUITE_H_ 2 | #define BOUNDED_QUEUE_SIGNATURES_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_signatures_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/SimpleThreadGotcha/src/SimpleThreadGotcha.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | using std::cout; 6 | using std::endl; 7 | 8 | std::thread t{[]{cout << "Hello Thread"<< endl;}}; 9 | cout << "Hello Main" << endl; 10 | } 11 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/BoundedQueue/src/bounded_queue_signatures_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_SIGNATURES_SUITE_H_ 2 | #define BOUNDED_QUEUE_SIGNATURES_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_signatures_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/BoundedBufferTestat/src/bounded_buffer_iterator_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_ITERATOR_SUITE_H_ 2 | #define BOUNDED_BUFFER_ITERATOR_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_iterator_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/BoundedBufferTestat/src/bounded_buffer_semantic_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_SEMANTIC_SUITE_H_ 2 | #define BOUNDED_BUFFER_SEMANTIC_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_semantic_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws09/BoundedBufferArray/src/bounded_buffer_semantic_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_SEMANTIC_SUITE_H_ 2 | #define BOUNDED_BUFFER_SEMANTIC_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_semantic_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/bounded_queue_student_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_STUDENT_SUITE_H_ 2 | #define BOUNDED_QUEUE_STUDENT_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_student_suite(); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/BoundedQueue/src/bounded_queue_student_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_STUDENT_SUITE_H_ 2 | #define BOUNDED_QUEUE_STUDENT_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_student_suite(); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /ws03/copycat/copycat.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(){ 5 | using input=std::istreambuf_iterator; 6 | input eof{}; 7 | input in{std::cin}; 8 | std::ostream_iterator out{std::cout}; 9 | copy(in,eof,out); 10 | } 11 | -------------------------------------------------------------------------------- /ws04/main_try_catch/README.md: -------------------------------------------------------------------------------- 1 | C++ allows try-catch blocks for function bodies. 2 | 3 | This implies, even main() can have such a try-catch function body. 4 | 5 | It looks unusual but is completely OK and could even provide 6 | a "graceful death" from a program throwing exceptions internally. -------------------------------------------------------------------------------- /ws05/enumDemo/README.md: -------------------------------------------------------------------------------- 1 | This project demonstrates definition and uses of enumeration types. 2 | 3 | *Note*: depending on Cevelop version, you might see "syntax errors" that aren't there. 4 | The code compiles clean. 5 | The Eclipse CDT C++ parser might not be up to all of C++11/14 syntax yet. -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws09/BoundedBufferArray/src/bounded_buffer_signatures_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_SIGNATURES_SUITE_H_ 2 | #define BOUNDED_BUFFER_SIGNATURES_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_signatures_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /exws09/algorithm_trivia/src/sorted_sequence_algorithms.h: -------------------------------------------------------------------------------- 1 | #ifndef SORTED_SEQUENCE_ALGORITHMS_H_ 2 | #define SORTED_SEQUENCE_ALGORITHMS_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_sorted_sequence_algorithms(); 7 | 8 | #endif /* SORTED_SEQUENCE_ALGORITHMS_H_ */ 9 | -------------------------------------------------------------------------------- /solws02/README.md: -------------------------------------------------------------------------------- 1 | Solutions for week 2 exercises, except for calc() 2 | 3 | The functions calc with their tests are part of the "Testat". 4 | 5 | *Note*: These solutions are bad C++, because they use their own loops. 6 | See week 3's solutions on how to solve these without own loop structures. 7 | -------------------------------------------------------------------------------- /solws02/averagei/averagei.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int sum{}; 4 | unsigned count{}; 5 | while(std::cin){ 6 | int val{}; 7 | if (std::cin >> val) ++count; 8 | sum += val; 9 | } 10 | if (count) std::cout << double(sum)/count << " average of integers\n"; 11 | } 12 | -------------------------------------------------------------------------------- /ws02/formatted_output/README.md: -------------------------------------------------------------------------------- 1 | This small example demonstrates some of the output formatting 2 | using manipulators on `std::ostream`. The manipulators taking arguments 3 | are declared in ``. It also shows the stickyness of some of the 4 | formatting manipulators are sticky and some not. -------------------------------------------------------------------------------- /ws12/biblicalfamily/Person.cpp: -------------------------------------------------------------------------------- 1 | #include "Person.h" 2 | #include 3 | 4 | void Person::print(std::ostream& out) const { 5 | out << "Person: "<< name << '\n'; 6 | out << " "; 7 | for(auto child:children){ 8 | out << child->name << ", "; 9 | } 10 | out << '\n'; 11 | } 12 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws02/02_05_optional_example/02_05_optional_example.exe.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/BoundedBufferTestat/src/bounded_buffer_signatures_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_SIGNATURES_SUITE_H_ 2 | #define BOUNDED_BUFFER_SIGNATURES_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_signatures_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/BoundedBufferTestat/src/bounded_buffer_student_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_STUDENT_SUITE_H_ 2 | #define BOUNDED_BUFFER_STUDENT_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_student_suite(); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws09/BoundedBufferArray/src/bounded_buffer_student_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_STUDENT_SUITE_H_ 2 | #define BOUNDED_BUFFER_STUDENT_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_student_suite(); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /exws09/algorithm_trivia/src/copy_and_replace_algorithms.h: -------------------------------------------------------------------------------- 1 | #ifndef COPY_AND_REPLACE_ALGORITHMS_H_ 2 | #define COPY_AND_REPLACE_ALGORITHMS_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_copy_and_replace_algorithms(); 7 | 8 | #endif /* COPY_AND_REPLACE_ALGORITHMS_H_ */ 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/bounded_queue_heap_memory_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_HEAP_MEMORY_SUITE_H_ 2 | #define BOUNDED_QUEUE_HEAP_MEMORY_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_heap_memory_suite(); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/bounded_queue_multi_threaded_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_MULTI_THREADED_SUITE_H_ 2 | #define BOUNDED_QUEUE_MULTI_THREADED_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_multi_threaded_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/SimpleThreadExample/src/SimpleThreadExample.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | using std::cout; 6 | using std::endl; 7 | 8 | std::thread t{[]{cout << "Hello Thread"<< endl;}}; 9 | cout << "Hello Main" << endl; 10 | t.join(); 11 | } 12 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/BoundedQueue/src/bounded_queue_heap_memory_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_HEAP_MEMORY_SUITE_H_ 2 | #define BOUNDED_QUEUE_HEAP_MEMORY_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_heap_memory_suite(); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/BoundedQueue/src/bounded_queue_multi_threaded_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_MULTI_THREADED_SUITE_H_ 2 | #define BOUNDED_QUEUE_MULTI_THREADED_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_multi_threaded_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws12_values_empty_etc/UnitsAsAggregates/UnitsAsAggregates.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /exws09/algorithm_trivia/src/fill_and_generate_algorithms.h: -------------------------------------------------------------------------------- 1 | #ifndef FILL_AND_GENERATE_ALGORITHMS_H_ 2 | #define FILL_AND_GENERATE_ALGORITHMS_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_fill_and_generate_algorithms(); 7 | 8 | #endif /* FILL_AND_GENERATE_ALGORITHMS_H_ */ 9 | -------------------------------------------------------------------------------- /exws09/algorithm_trivia/src/property_checking_algorithms.h: -------------------------------------------------------------------------------- 1 | #ifndef PROPERTY_CHECKING_ALGORITHMS_H_ 2 | #define PROPERTY_CHECKING_ALGORITHMS_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_property_checking_algorithms(); 7 | 8 | #endif /* PROPERTY_CHECKING_ALGORITHMS_H_ */ 9 | -------------------------------------------------------------------------------- /exws10/wseventh/src/wseventh.cpp: -------------------------------------------------------------------------------- 1 | #include "wseventh.h" 2 | 3 | #include 4 | #include 5 | 6 | void wseventh(std::istream & in, std::ostream & out) { 7 | //TODO: Implement your wseventh functionality here 8 | out << "At least seven different words expected in input.\n"; 9 | } 10 | -------------------------------------------------------------------------------- /ws11/SackScrabble/nikolaus.cpp: -------------------------------------------------------------------------------- 1 | #include "Sack.h" 2 | 3 | struct Present {}; 4 | 5 | class SantaClaus { 6 | Sack theSackFullOfPresents; 7 | } santa; 8 | 9 | struct Potatoes{}; 10 | struct PotatoChips{}; 11 | Sack> ZweifelFactory(std::vector>); 12 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/bounded_queue_default_behavior_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_DEFAULT_BEHAVIOR_SUITE_H_ 2 | #define BOUNDED_QUEUE_DEFAULT_BEHAVIOR_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_default_behavior_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/BoundedQueue/src/bounded_queue_default_behavior_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_DEFAULT_BEHAVIOR_SUITE_H_ 2 | #define BOUNDED_QUEUE_DEFAULT_BEHAVIOR_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_default_behavior_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws13_ref_poly/Pointers/Pointers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /solws02/averagef/averagef.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | double sum{}; 4 | unsigned count{}; 5 | while(std::cin){ 6 | double val{}; 7 | if (std::cin >> val) ++count; 8 | sum += val; 9 | } 10 | if (count) std::cout << sum/count << " average of floating point numbers\n"; 11 | } 12 | -------------------------------------------------------------------------------- /ws04/move_enabled/README.md: -------------------------------------------------------------------------------- 1 | This project tries to demonstrate the difference of using a non-movable type that requires copies 2 | and a move-enabled type. 3 | 4 | This is bad code on only used to demonstrate the effect. 5 | 6 | copying seems to be 3 times slower with the current parameters than move on my machine. -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/inheritance_SFINAE_example/src/inheritance_SFINAE_example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | template 6 | 7 | 8 | int main() { 9 | cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!! 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /solws04/wlist/README.md: -------------------------------------------------------------------------------- 1 | This is the canonical solution using the appropriate data structures. 2 | 3 | For the case-less comparing one could parameterize std::set, 4 | but the feature to so is not yet explained. Therfore wlist_caseless 5 | shows an alternative solution using different algorithms and a sorted 6 | vector. -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws04/04_08_bad_decl_type/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | decltype(auto) f1() { 4 | int x = 23; 5 | return (x); // returning reference to local variable 6 | } 7 | 8 | int main(int argc, char **argv) { 9 | 10 | std::cout << f1() << std::endl; // undefined behavior 11 | } 12 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/BoundedBufferTestat/src/bounded_buffer_default_behavior_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_DEFAULT_BEHAVIOR_SUITE_H_ 2 | #define BOUNDED_BUFFER_DEFAULT_BEHAVIOR_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_default_behavior_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/BoundedBufferTestat/src/bounded_buffer_heap_memory_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_HEAP_MEMORY_SUITE_H_ 2 | #define BOUNDED_BUFFER_HEAP_MEMORY_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_heap_memory_suite(); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws09/BoundedBufferArray/src/bounded_buffer_default_behavior_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_DEFAULT_BEHAVIOR_SUITE_H_ 2 | #define BOUNDED_BUFFER_DEFAULT_BEHAVIOR_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_default_behavior_suite(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws09/DemoTerminate/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct Ball { 4 | }; 5 | 6 | void pitcher() noexcept { 7 | throw Ball{}; 8 | } 9 | 10 | int main() { 11 | try { 12 | pitcher(); 13 | } catch(Ball const & b) { 14 | std::cout << "caught the ball!"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws12_values_empty_etc/Pointers/Pointers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /exws09/algorithm_trivia/src/remove_unique_rotate_algorithms.h: -------------------------------------------------------------------------------- 1 | #ifndef REMOVE_UNIQUE_ROTATE_ALGORITHMS_H_ 2 | #define REMOVE_UNIQUE_ROTATE_ALGORITHMS_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_remove_unique_rotate_algorithms(); 7 | 8 | #endif /* REMOVE_UNIQUE_ROTATE_ALGORITHMS_H_ */ 9 | -------------------------------------------------------------------------------- /solws02/wc/wc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | unsigned wc(std::istream & input) { 5 | unsigned count{0}; 6 | std::string word{}; 7 | while (input >> word) { 8 | count++; 9 | } 10 | return count; 11 | } 12 | 13 | int main() { 14 | std::cout << wc(std::cin); 15 | } 16 | -------------------------------------------------------------------------------- /solws13/GardeningLib/Shapes.h: -------------------------------------------------------------------------------- 1 | #ifndef SHAPES_H_ 2 | #define SHAPES_H_ 3 | 4 | #include "Shapes/Rectangle.h" 5 | #include "Shapes/Diamond.h" 6 | #include "Shapes/Square.h" 7 | #include "Shapes/Triangle.h" 8 | #include "Shapes/Circle.h" 9 | #include "Shapes/Ellipse.h" 10 | 11 | #endif /* SHAPES_H_ */ 12 | -------------------------------------------------------------------------------- /ws02/how_old_are_you_robust/README.md: -------------------------------------------------------------------------------- 1 | This example program shows a more robust way to enter integers 2 | from a `std::istream` by reading in a string first and then 3 | parsing it either through a `std::istringstream` checking for 4 | its failuere or via 5 | `std::stoi()` which will cause an exception if it can not convert. -------------------------------------------------------------------------------- /ws03/cat/cat.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | int main(){ 6 | using input=std::istream_iterator; 7 | input eof{}; 8 | input in{std::cin}; 9 | std::ostream_iterator out{std::cout," "}; 10 | copy(in,eof,out); 11 | } 12 | -------------------------------------------------------------------------------- /ws05/enumDemo/Statemachine.h: -------------------------------------------------------------------------------- 1 | #ifndef STATEMACHINE_H_ 2 | #define STATEMACHINE_H_ 3 | 4 | struct Statemachine { 5 | Statemachine(); 6 | void processInput(char c); 7 | bool isDone() const; 8 | private: 9 | enum class State : unsigned short; 10 | State theState; 11 | }; 12 | 13 | #endif /* STATEMACHINE_H_ */ 14 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/BoundedBufferTestat/src/bounded_buffer_student_suite.cpp: -------------------------------------------------------------------------------- 1 | #include "bounded_buffer_student_suite.h" 2 | #include "cute.h" 3 | 4 | //TODO: Add your own tests here 5 | 6 | cute::suite make_suite_bounded_buffer_student_suite(){ 7 | cute::suite s; 8 | return s; 9 | } 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w6/FibonacciIterator/src/FibonacciIterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FibonacciIterator.h 3 | * 4 | * Created on: 08.04.2016 5 | * Author: sop 6 | */ 7 | 8 | #ifndef SRC_FIBONACCIITERATOR_H_ 9 | #define SRC_FIBONACCIITERATOR_H_ 10 | 11 | 12 | 13 | 14 | 15 | #endif /* SRC_FIBONACCIITERATOR_H_ */ 16 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/shoppinglist.h: -------------------------------------------------------------------------------- 1 | #ifndef SHOPPINGLIST_H_ 2 | #define SHOPPINGLIST_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | using ShapePtr=std::shared_ptr; 8 | void printShoppingList(std::vector, std::ostream&); 9 | 10 | #endif /* SHOPPINGLIST_H_ */ 11 | -------------------------------------------------------------------------------- /solws09/wcount_solution/src/wcount.cpp: -------------------------------------------------------------------------------- 1 | #include "wcount.h" 2 | #include "word.h" 3 | 4 | #include 5 | #include 6 | 7 | unsigned wcount(std::istream& in) { 8 | using word_iterator = std::istream_iterator; 9 | return std::distance(word_iterator{in}, word_iterator{}); 10 | } 11 | -------------------------------------------------------------------------------- /ws02/how_old_are_you_robust_ignoring/README.md: -------------------------------------------------------------------------------- 1 | This is another way to more robustly read an integer from a std::stream 2 | by ignoring invalid characters after the reading of an int failed 3 | and trying again. As one option it shows how to ignore input characters 4 | up to a line break (regardless of how long the line might be). -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws09/BoundedBufferArray/src/bounded_buffer_content_suite_no_default.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_CONTENT_SUITE_NO_DEFAULT_H_ 2 | #define BOUNDED_BUFFER_CONTENT_SUITE_NO_DEFAULT_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_content_suite_no_default(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /solws13/topological_sort_lib/README.md: -------------------------------------------------------------------------------- 1 | This is a very slow and primitive implementation of the topological sort problem. 2 | 3 | It takes "modules" by level from a set and allows to print out these levels, 4 | based on the dependencies given as input. 5 | 6 | see topological_sort_fast for a faster solution that works more efficient. -------------------------------------------------------------------------------- /ws08/ex_time_container_performance/timer.cpp: -------------------------------------------------------------------------------- 1 | #include "timer.h" 2 | 3 | std::chrono::microseconds time_func(void (f)()){ 4 | using namespace std::chrono; 5 | high_resolution_clock clock{}; 6 | auto start=clock.now(); 7 | f(); 8 | auto end = clock.now(); 9 | return duration_cast(end - start); 10 | } 11 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws09/BoundedBufferArray/src/bounded_buffer_semantic_suite_no_default.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_SEMANTIC_SUITE_NO_DEFAULT_H_ 2 | #define BOUNDED_BUFFER_SEMANTIC_SUITE_NO_DEFAULT_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_semantic_suite_no_default(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/multiplication_table_loops/src/multiplication_table_loops.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | for (int i=1; i <=20; ++i){ 7 | cout << '\n'; 8 | for (int j=1; j <=20; ++j) 9 | cout << setw(4) << j*i ; 10 | } 11 | cout << '\n'; 12 | } 13 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/multiplication_table_loops/src/multiplication_table_loops.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | for (int i=1; i <=20; ++i){ 7 | cout << '\n'; 8 | for (int j=1; j <=20; ++j) 9 | cout << setw(4) << j*i ; 10 | } 11 | cout << '\n'; 12 | } 13 | -------------------------------------------------------------------------------- /solws06/SimulatedToggleButtonWithTest/README.md: -------------------------------------------------------------------------------- 1 | This is a demonstrator for using enum class with forward declaration and hidden state. 2 | 3 | If you load this code into Cevelop/CDT you will see syntax errors, since at the time 4 | of this writing forward declarations of enum class types are not yet implemented by 5 | the CDT parser. 6 | -------------------------------------------------------------------------------- /ws05/RingModulo5MixedArithmetic/README.md: -------------------------------------------------------------------------------- 1 | This version of RinModulo5 demonstrates the DIY implementation of operators for mixed arithmetic 2 | with unsigned. It also demonstrates how binary operators can be implemented in different means. 3 | 4 | *Note:* The mixed arithmetic can lead to ambiguities, when combined with automatic conversion. -------------------------------------------------------------------------------- /ws08/mapcountwords/countwords.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(){ 5 | std::map words; 6 | std::string s; 7 | while (std::cin >> s && s != ".") 8 | ++words[s]; 9 | for(auto const &p:words) 10 | std::cout << p.first << " = "<< p.second << '\n'; 11 | } 12 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws12/HairpollClient/result.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
    5 |
  • - 1
  • 6 |
  • - 2
  • 7 |
8 | 9 | 10 | -------------------------------------------------------------------------------- /CppAdvanced/other/user_defined_literals/src/velocity.hpp: -------------------------------------------------------------------------------- 1 | #ifndef VELOCITY_HPP_ 2 | #define VELOCITY_HPP_ 3 | 4 | namespace velocity { 5 | 6 | struct speed { 7 | constexpr 8 | explicit 9 | speed(double kmh) : 10 | kmh { kmh } {} 11 | double const kmh; 12 | }; 13 | 14 | } 15 | 16 | #endif /* VELOCITY_HPP_ */ 17 | -------------------------------------------------------------------------------- /ws05/TracerDemo/README.md: -------------------------------------------------------------------------------- 1 | This class demonstrates the effects of construction, copying and deterministic object lifetime 2 | by tracing also the destructor. 3 | 4 | *Note*: normally one would not implement copy-constructors and destructors but rely on the automatically 5 | provided ones. This code is not meant to be an example for own types. -------------------------------------------------------------------------------- /ws05/TracerMoveDemo/README.md: -------------------------------------------------------------------------------- 1 | This class demonstrates the effects of construction, moving and deterministic object lifetime 2 | by tracing also the destructor. 3 | 4 | *Note*: normally one would not implement move-constructors and destructors but rely on the automatically 5 | provided ones. This code is not meant to be an example for own types. -------------------------------------------------------------------------------- /ws08/unordered_example/unorderedmap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(){ 5 | std::unordered_map words; 6 | std::string s; 7 | while (std::cin >> s) 8 | ++words[s]; 9 | for(auto const &p:words) 10 | std::cout << p.first << " = "<< p.second << '\n'; 11 | } 12 | -------------------------------------------------------------------------------- /ws11/checkODRviolationOfstaticMember/templatewithstaticmember.h: -------------------------------------------------------------------------------- 1 | #ifndef TEMPLATEWITHSTATICMEMBER_H_ 2 | #define TEMPLATEWITHSTATICMEMBER_H_ 3 | template 4 | struct staticmember{ 5 | static int dummy; 6 | }; 7 | template 8 | int staticmember::dummy{sizeof(T)}; 9 | #endif /* TEMPLATEWITHSTATICMEMBER_H_ */ 10 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/bounded_queue_single_threaded_lock_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_SINGLE_THREADED_LOCK_SUITE_H_ 2 | #define BOUNDED_QUEUE_SINGLE_THREADED_LOCK_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_single_threaded_lock_suite(); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/BoundedQueue/src/bounded_queue_single_threaded_lock_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_SINGLE_THREADED_LOCK_SUITE_H_ 2 | #define BOUNDED_QUEUE_SINGLE_THREADED_LOCK_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_single_threaded_lock_suite(); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/BedFactory.h: -------------------------------------------------------------------------------- 1 | #ifndef BEDFACTORY_H_ 2 | #define BEDFACTORY_H_ 3 | #include 4 | #include 5 | #include 6 | using ShapePtr=std::shared_ptr; 7 | ShapePtr makeBed(std::istream &in); 8 | 9 | std::vector createAllBeds(std::istream &in); 10 | #endif /* BEDFACTORY_H_ */ 11 | -------------------------------------------------------------------------------- /solws13/echor/README.md: -------------------------------------------------------------------------------- 1 | This program solves the following exercise in two ways, just doubling the output: 2 | 3 | Write a C++ program __echor__ that produces a list of its program arguments 4 | in reverse order without using a hand-written loop or recursion. 5 | ``` 6 | $ echor zero one two three 7 | three 8 | two 9 | one 10 | zero 11 | ``` -------------------------------------------------------------------------------- /ws04/namespacesyntax/anonymousnamespace.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace { // anonymous 3 | void doit(){ // can not be called outside this file 4 | std::cout << "doit called\n"; 5 | } 6 | } // anonymous namespace ends 7 | void print(){ // callable from other parts if declared 8 | doit(); 9 | std::cout << "print called\n"; 10 | } 11 | -------------------------------------------------------------------------------- /ws05/Date/Date2.h: -------------------------------------------------------------------------------- 1 | #ifndef DATE_H_ 2 | #define DATE_H_ 3 | 4 | class Date { 5 | public: 6 | int year, month, day; 7 | //... 8 | Date(int year, int month, int day) : 9 | year { year }, month { month }, day { day } { 10 | // should check here. 11 | } 12 | }; 13 | 14 | Date myBirthday { 1964, 12, 24 }; 15 | #endif /* DATE_H_ */ 16 | -------------------------------------------------------------------------------- /ws08/setexample/vowelsset.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void filtervowels(std::istream &in, std::ostream &out){ 4 | std::set const vowels{'a','e','o','u','i','y'}; 5 | char c{}; 6 | while (in>>c) 7 | if (! vowels.count(c)) 8 | out << c; 9 | } 10 | int main(){ 11 | filtervowels(std::cin,std::cout); 12 | } 13 | -------------------------------------------------------------------------------- /ws09/demofunctionwithmember/demofunctionwithmember.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct X { 5 | int calc(int i) const { return x*i; } 6 | private: 7 | int x{7}; 8 | }; 9 | 10 | int main(){ 11 | std::function const f{&X::calc}; 12 | X const anX{}; 13 | std::cout << f(anX,6); 14 | } 15 | -------------------------------------------------------------------------------- /ws02/bad_relational_operator_example/README.md: -------------------------------------------------------------------------------- 1 | **Never** ever program this way, it shows how bool converts to an int and thus 2 | make combining several relational operators in a syntactically valid expression, 3 | which is always not what a naive programmer would expect. 4 | 5 | This code is provided only for completeness of the lecture's example code. -------------------------------------------------------------------------------- /ws09/functordemo/functordemo.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | struct donothingfunctor{ 11 | void operator()()const{} 12 | }; 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | int main(){ 31 | donothingfunctor const f{}; 32 | f(); 33 | donothingfunctor{}(); 34 | } 35 | -------------------------------------------------------------------------------- /ws10/MinWithDefaultTemplateArgument/src/MyMax.h: -------------------------------------------------------------------------------- 1 | #ifndef MYMAX_H_ 2 | #define MYMAX_H_ 3 | #include 4 | namespace MyMax{ 5 | template 6 | typename std::common_type::type 7 | max(T const &a, U const & b){ 8 | return a < b ? b : a; 9 | } 10 | 11 | } 12 | 13 | #endif /* MYMAX_H_ */ 14 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws06/nullptr_vs_null/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct S{}; 4 | 5 | void bar(int i) { 6 | std::cout << "bar(int)\n"; 7 | } 8 | 9 | void bar(S * ps) { 10 | std::cout << "bar(S *)\n"; 11 | } 12 | 13 | 14 | int main(int argc, char **argv) { 15 | bar(0); 16 | bar(NULL); //surprising 17 | bar(nullptr); 18 | } 19 | -------------------------------------------------------------------------------- /CppAdvanced/other/user_defined_literals/user_defined_literals.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ws02/bad_relational_operator_example/bad_relational_operator_example.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | std::cout << "enter a number : " ; 5 | int a{}; 6 | std::cin >> a; 7 | if (0 3 | 4 | int foo(); 5 | 6 | int main(){ 7 | std::cout << staticmember::dummy << '\n'; 8 | std::cout << staticmember::dummy << '\n'; 9 | std::cout << foo() << '\n'; 10 | std::cout << staticmember::dummy << '\n'; 11 | } 12 | -------------------------------------------------------------------------------- /ws12/biblicalfamily/README.md: -------------------------------------------------------------------------------- 1 | This directory contains code demonstrating using shared_ptr 2 | for implementing object relationships. 3 | 4 | This is the first step, showing how to use shared_ptr. 5 | 6 | NB: there are three more versions demonstrating modifications 7 | when cyclic relationships, e.g., between parents and children 8 | in a family, are represented. -------------------------------------------------------------------------------- /ws10/shiftoperator/shiftoperator.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | thisIsATest: 0 == i expected: 0 but was: 1 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ws12/PIMPLexample/Wizard.h: -------------------------------------------------------------------------------- 1 | #ifndef WIZARD_H_ 2 | #define WIZARD_H_ 3 | #include 4 | #include 5 | namespace Pimpl { 6 | 7 | class Wizard { 8 | std::shared_ptr pImpl; 9 | public: 10 | Wizard(std::string name); 11 | std::string doMagic(std::string wish); 12 | }; 13 | 14 | } /* namespace Pimpl */ 15 | #endif /* WIZARD_H_ */ 16 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/bounded_queue_student_suite.cpp: -------------------------------------------------------------------------------- 1 | #include "bounded_queue_student_suite.h" 2 | 3 | #include "BoundedQueue.h" 4 | #include "cute.h" 5 | 6 | //TODO: Add your own tests here 7 | 8 | 9 | 10 | 11 | cute::suite make_suite_bounded_queue_student_suite(){ 12 | cute::suite s; 13 | return s; 14 | } 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/BoundedQueue/src/bounded_queue_student_suite.cpp: -------------------------------------------------------------------------------- 1 | #include "bounded_queue_student_suite.h" 2 | 3 | #include "BoundedQueue.h" 4 | #include "cute.h" 5 | 6 | //TODO: Add your own tests here 7 | 8 | 9 | 10 | 11 | cute::suite make_suite_bounded_queue_student_suite(){ 12 | cute::suite s; 13 | return s; 14 | } 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws14/iterator/iterator.cpp: -------------------------------------------------------------------------------- 1 | #include "iterator.h" 2 | #include 3 | #include 4 | 5 | int main(){ 6 | std::vector v{3,1,4,1,5,9,2,6}; 7 | mysort(v.begin(),v.end()); 8 | std::list l{3,1,4,1,5,9,2,6}; 9 | mysort(begin(l),end(l)); // concept check fails 10 | // std::sort(l.begin(),l.end()); // horrible compile error 11 | } 12 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/Cpp11compileTimeComputation/Cpp11compileTimeComputation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws03/03_05_temporary_materialization/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct Ghost { 4 | void haunt() const { 5 | std::cout << "booooo!\n"; 6 | } 7 | //~Ghost() = delete; 8 | }; 9 | 10 | Ghost evoke() { 11 | return Ghost{}; 12 | } 13 | 14 | 15 | int main() { 16 | Ghost && sam = evoke(); 17 | 18 | Ghost{}.haunt(); 19 | } 20 | -------------------------------------------------------------------------------- /solws11/rotate3arguments_solution/src/rotate3arguments.h: -------------------------------------------------------------------------------- 1 | #ifndef ROTATE3ARGUMENTS_H_ 2 | #define ROTATE3ARGUMENTS_H_ 3 | 4 | #include 5 | 6 | template 7 | void rotate3arguments(T &a, T& b, T& c) { 8 | std::swap(a, b); // using swap avoids unnecessary copying and temporaries 9 | std::swap(b, c); 10 | } 11 | 12 | #endif /* ROTATE3ARGUMENTS_H_ */ 13 | -------------------------------------------------------------------------------- /ws05/RingModulo5InOutConversion/README.md: -------------------------------------------------------------------------------- 1 | In addition to demonstrating operator overloading using Boost.operators shorthand 2 | this class also demonstrates a non-explicit conversion constructor and type conversion operator. 3 | 4 | *Note*: normally such conversion operators should be explicit to avoid automatic compiler conversions 5 | in mixed expressions and resulting ambiguities. -------------------------------------------------------------------------------- /solws08/anagram_multiword/README.md: -------------------------------------------------------------------------------- 1 | Simple solution for anagrams 2 | 3 | The answer for the real words in tha anagrams for the word "listen" is 4 | 5 | * enlist 6 | * listen 7 | * silent 8 | * tinsel 9 | 10 | for "I am on vacation": 11 | ` 12 | I am on vacation 13 | aaaciimnnootv: I am on vacation 14 | 145matching words in set 15 | 517024 anagrams found 16 | 6.76936s time 17 | ` -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws14/non_addable/non_addable.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "addable_sum.h" 5 | 6 | struct X{}; 7 | 8 | int main(){ 9 | std::vector v(20); 10 | iota(v.begin(),v.end(),1); 11 | std::cout << sum(v.begin(),v.end(),X{}) << '\n'; 12 | std::cout << add("hallo\n",2); 13 | std::cout << add(2,"hallo\n"); 14 | } 15 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/array_std_array/array_std_array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void foo(int a[]){ 4 | // how big is a? it is a pointer only 5 | } 6 | 7 | template 8 | void bar(std::array a){ 9 | } 10 | 11 | int main(){ 12 | int cube[6]{1,2,3,4,5,6}; 13 | std::array cubea{{1,2,3,4,5,6}}; 14 | foo(cube); 15 | bar(cubea); 16 | } 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /solws08/anagram_multiword_opt/README.md: -------------------------------------------------------------------------------- 1 | Simple solution for anagrams 2 | 3 | The answer for the real words in tha anagrams for the word "listen" is 4 | 5 | * enlist 6 | * listen 7 | * silent 8 | * tinsel 9 | 10 | for "I am on vacation": 11 | ` 12 | I am on vacation 13 | aaaciimnnootv: I am on vacation 14 | 145matching words in set 15 | 517024 anagrams found 16 | 2.16449s time 17 | ` -------------------------------------------------------------------------------- /ws04/move_overload_demo/README.md: -------------------------------------------------------------------------------- 1 | This (very bad!) example code demonstrates the different overload resolutions 2 | for rvalues and lvalues. It was inspired by Olve Maudal's C++ Pub Quiz. 3 | 4 | _**Don't do this at home, it is exposition only code, not to be used outside this example.**_ 5 | 6 | You can use Templator (Template Information View) to visualize the respective overloads selected. -------------------------------------------------------------------------------- /solws04/wlist/wlist.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(){ 8 | using in=std::istream_iterator; 9 | std::set wlist{in{std::cin},in{}}; 10 | copy(begin(wlist),end(wlist), 11 | std::ostream_iterator{std::cout,"\n"}); 12 | 13 | } 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ws12/demonstrate_new_delete/README.md: -------------------------------------------------------------------------------- 1 | This project only exists to introduce new/delete syntax. 2 | 3 | DO NOT USE neither new nor delete in your own classes or code 4 | use unique_ptr/make_unique or shared_ptr/make_shared instead. 5 | 6 | ...unless you are implementing your own version of standard library like 7 | classes, such as variant or optional that might require 8 | placement new. -------------------------------------------------------------------------------- /solws09/wdiffcount_solution/src/wdiffcount.cpp: -------------------------------------------------------------------------------- 1 | #include "wdiffcount.h" 2 | #include "word.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | unsigned wdiffcount(std::istream& in) { 9 | using word_iterator = std::istream_iterator; 10 | std::set words{word_iterator{in}, word_iterator{}}; 11 | return words.size(); 12 | } 13 | -------------------------------------------------------------------------------- /ws08/mapcountvowels/countvowels.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(){ 5 | std::map vowels 6 | {{'a',0},{'e',0},{'i',0},{'o',0},{'u',0},{'y',0}}; 7 | char c; 8 | while (std::cin >> c) 9 | if (vowels.count(c)) 10 | ++vowels[c]; 11 | for(auto const &p:vowels) 12 | std::cout << p.first << " = "<< p.second << '\n'; 13 | } 14 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws03/can_be_moved_from/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | struct S {}; 5 | 6 | void foo(S && s) { 7 | //do something fancy with s 8 | } 9 | 10 | int main() 11 | { 12 | S s{}; 13 | foo(S{}); //From S{} can be moved 14 | //foo(s); //From s cannot be moved directly 15 | foo(std::move(s)); //std::move converts s into something movable 16 | } 17 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11b_MI/MI_Ambiguities/MI_Ambiguities.cpp: -------------------------------------------------------------------------------- 1 | class BaseX { 2 | void foo() {} //private 3 | }; 4 | 5 | struct BaseY { 6 | void foo() {} //public 7 | }; 8 | 9 | struct Derived : BaseX, BaseY {}; 10 | 11 | 12 | int main(int argc, char **argv) { 13 | Derived d{}; 14 | d.foo(); //ambiguous 15 | d.BaseX::foo(); //not accessible 16 | d.BaseY::foo(); //works 17 | } 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [CPlusPlusLecture](https://wiki.ifs.hsr.ch/CPlusPlus) 2 | 3 | This repository is used to provide all source code shown in my (basic) C++ lecture. 4 | 5 | It contains Cevelop workspaces on a per week basis for the 14 weeks. ws01..ws14 6 | 7 | Please submit pull requests for bugs or suggestions. 8 | 9 | The rest of the lecture's information is kept at https://wiki.ifs.hsr.ch/CPlusPlus 10 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/Square.h: -------------------------------------------------------------------------------- 1 | #ifndef SQUARE_H_ 2 | #define SQUARE_H_ 3 | 4 | #include "Shape.h" 5 | #include 6 | class Square: public Shape { 7 | double length; 8 | public: 9 | Square(double len); 10 | Square(std::istream&); 11 | unsigned int pegs() const; 12 | double rope() const; 13 | double seeds() const; 14 | std::string name() const; 15 | }; 16 | 17 | #endif /* SQUARE_H_ */ 18 | -------------------------------------------------------------------------------- /ws04/namespacesyntax/namespacesyntax.cpp: -------------------------------------------------------------------------------- 1 | namespace demo{ 2 | void foo(); //1 3 | namespace subdemo{ 4 | void foo(){/*2*/} 5 | } // subdemo 6 | } // demo 7 | namespace demo{ 8 | void bar(){ 9 | foo(); //1 10 | subdemo::foo();//2 11 | } 12 | } 13 | void demo::foo(){/*1*/} // definition 14 | int main(){ 15 | using ::demo::subdemo::foo; 16 | foo();//2 17 | demo::foo();//1 18 | demo::bar(); 19 | } 20 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/bounded_queue_non_default_constructible_element_type_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_NON_DEFAULT_CONSTRUCTIBLE_ELEMENT_TYPE_SUITE_H_ 2 | #define BOUNDED_QUEUE_NON_DEFAULT_CONSTRUCTIBLE_ELEMENT_TYPE_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_non_default_constructible_element_type_suite(); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/BoundedQueue/src/bounded_queue_non_default_constructible_element_type_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_QUEUE_NON_DEFAULT_CONSTRUCTIBLE_ELEMENT_TYPE_SUITE_H_ 2 | #define BOUNDED_QUEUE_NON_DEFAULT_CONSTRUCTIBLE_ELEMENT_TYPE_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_queue_non_default_constructible_element_type_suite(); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws03/why_rvalue_might_be_on_the_lhs/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct S { 5 | S& operator=(std::string const & s) /*&*/ { // & prohibits calling non-const member functions on temporaries 6 | std::cout << "got \"" << s << "\" assigned\n"; 7 | return *this; 8 | } 9 | }; 10 | 11 | int main(int argc, char **argv) { 12 | S{} = "new value"; 13 | } 14 | -------------------------------------------------------------------------------- /ws04/chapter_function_syntax/returnreference.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | std::ostream &print(std::ostream &out, int value){ 11 | out << value; 12 | return out; 13 | } 14 | 15 | 16 | 17 | 18 | 19 | 20 | void usePrint(){ 21 | if (print(std::cout,42)){ 22 | std::cout << " printed OK\n"; 23 | } else { 24 | std::cerr << "couldn't print on cout\n"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws01/00_01_CtylecheckerDemo/src/header.h: -------------------------------------------------------------------------------- 1 | #ifndef SRC_HEADER_H_ //Include Guard 2 | #define SRC_HEADER_H_ 3 | 4 | //iostream header 5 | //#include 6 | 7 | //Global non-const 8 | //int the_devil{}; 9 | 10 | 11 | //void print_on_console(std::string const output) { 12 | // std::cout << output; 13 | //} 14 | 15 | //Using directives in headers 16 | //using namespace std; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/BoundedBufferTestat/src/bounded_buffer_non_default_constructible_element_type_suite.h: -------------------------------------------------------------------------------- 1 | #ifndef BOUNDED_BUFFER_NON_DEFAULT_CONSTRUCTIBLE_ELEMENT_TYPE_SUITE_H_ 2 | #define BOUNDED_BUFFER_NON_DEFAULT_CONSTRUCTIBLE_ELEMENT_TYPE_SUITE_H_ 3 | 4 | #include "cute_suite.h" 5 | 6 | extern cute::suite make_suite_bounded_buffer_non_default_constructible_element_type_suite(); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /ws08/demo_accumulate_string/accumulatestring.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | int main(){ 10 | 11 | using in=std::istream_iterator; 12 | std::vector v{in{std::cin},in{}}; 13 | auto s=accumulate(cbegin(v),cend(v),std::string{}); 14 | std::cout << s; 15 | } 16 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/Tailor/Tailor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/Fibo_CPP14_constexpr/Fibo_CPP14_constexpr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | thisIsATest: check(std::integral_constant<int,-1>()) 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ws10/minwithtemplateandoverloads/MyMin.h: -------------------------------------------------------------------------------- 1 | #ifndef MYMIN_H_ 2 | #define MYMIN_H_ 3 | namespace MyMin{ 4 | template 5 | T const& min(T const& a, T const& b){ 6 | return (a < b)? a : b ; 7 | } 8 | template 9 | T const * min(T const* a, T const* b){ 10 | return (*a < *b)? a : b ; 11 | } 12 | char const * min(char const* a, char const* b); 13 | 14 | } 15 | 16 | #endif /*MYMIN_H_*/ 17 | -------------------------------------------------------------------------------- /ws12/PIMPLexample/Wizard_unique_ptr.h: -------------------------------------------------------------------------------- 1 | #ifndef WIZARD_H_ 2 | #define WIZARD_H_ 3 | #include 4 | #include 5 | namespace PimplUnique { 6 | 7 | class Wizard { 8 | std::unique_ptr pImpl; 9 | public: 10 | Wizard(std::string name); 11 | ~Wizard(); // must declare dtor 12 | std::string doMagic(std::string wish); 13 | }; 14 | 15 | } /* namespace PimplUnique */ 16 | #endif /* WIZARD_H_ */ 17 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/BoundedQueue/src/times_literal.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TIMES_LITERAL_HPP_ 2 | #define TIMES_LITERAL_HPP_ 3 | 4 | namespace times { 5 | namespace literal { 6 | 7 | constexpr auto operator"" _times(unsigned long long n) { 8 | return [n](auto f){ 9 | for (auto i = 0u; i < n; i++) { 10 | f(); 11 | } 12 | }; 13 | } 14 | 15 | } 16 | } 17 | 18 | 19 | 20 | #endif /* TIMES_LITERAL_HPP_ */ 21 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/BoundedQueue/src/times_literal.hpp: -------------------------------------------------------------------------------- 1 | #ifndef TIMES_LITERAL_HPP_ 2 | #define TIMES_LITERAL_HPP_ 3 | 4 | namespace times { 5 | namespace literal { 6 | 7 | constexpr auto operator"" _times(unsigned long long n) { 8 | return [n](auto f){ 9 | for (auto i = 0u; i < n; i++) { 10 | f(); 11 | } 12 | }; 13 | } 14 | 15 | } 16 | } 17 | 18 | 19 | 20 | #endif /* TIMES_LITERAL_HPP_ */ 21 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/Tailor/Tailor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ws04/move_only/README.md: -------------------------------------------------------------------------------- 1 | This (very bad!) example code demonstrates the different overload resolutions 2 | for rvalues and lvalues of some move-only type and demonstrates the usage of when 3 | a move constructor is actually called. 4 | 5 | _**Don't do this at home, it is exposition only code, not to be used outside this example.**_ 6 | 7 | You can use Templator (Template Information View) to visualize the respective overloads selected. -------------------------------------------------------------------------------- /ws08/countvowelsmultiset/countvowelsmultiset.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(){ 5 | std::set vowels{'a','e','i','o','u','y'}; 6 | std::multiset allvowels; 7 | char c; 8 | while (std::cin >> c) 9 | if (vowels.count(c)) 10 | allvowels.insert(c); // map 11 | for(char v:vowels){ 12 | std::cout << v << " = "<< allvowels.count(v)<<'\n'; 13 | } // reduce 14 | } 15 | -------------------------------------------------------------------------------- /ws08/unordered_mapcountvowels/unorderedcountvowels.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(){ 5 | std::unordered_map vowels 6 | {{'a',0},{'e',0},{'i',0},{'o',0},{'u',0},{'y',0}}; 7 | char c; 8 | while (std::cin >> c) 9 | if (vowels.count(c)) 10 | ++vowels[c]; 11 | for(auto const &p:vowels) 12 | std::cout << p.first << " = "<< p.second << '\n'; 13 | } 14 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws03/copy_elision_exceptions/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct S { 5 | S() { 6 | std::cout << "creating S\n"; 7 | } 8 | 9 | // S(S const &) = delete; 10 | 11 | S(S const &) noexcept { 12 | std::cout << "copying S\n"; 13 | } 14 | }; 15 | 16 | 17 | int main() { 18 | try { 19 | S s{}; 20 | throw s; 21 | } catch (S s) { 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /ws08/unorderedsetremovevowels/removevowels.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | int main(){ 6 | std::unordered_set const vwl{'a','e','i','o','u'}; 7 | using in=std::istreambuf_iterator; 8 | using out=std::ostreambuf_iterator; 9 | remove_copy_if(in{std::cin},in{},out{std::cout}, 10 | [vwl](char c){return vwl.count(c);}); 11 | } 12 | -------------------------------------------------------------------------------- /ws12/biblicalfamily2/README.md: -------------------------------------------------------------------------------- 1 | This directory contains code demonstrating using shared_ptr 2 | for implementing object relationships. 3 | 4 | This is the second step, showing the wrong use of shared_ptr for 5 | cyclic relationships that results in objects no longer deleted. 6 | 7 | NB: there are three more versions demonstrating modifications 8 | when cyclic relationships, e.g., between parents and children 9 | in a family, are represented. -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws12_values_empty_etc/WholeValue/WholeValue.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws02/02_01_static_assert/static_assert.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | template 5 | T negate(T t) { 6 | static_assert(std::is_signed_v); 7 | static_assert(std::is_signed_v, "negate can only be called on signed types"); 8 | return -t; 9 | } 10 | 11 | 12 | int main() { 13 | int answer = 42; 14 | negate(answer); 15 | 16 | unsigned weight = 100; 17 | negate(weight); 18 | } 19 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws02/02_09_structured_binding/structured_binding.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct S { 5 | int member_i; 6 | double member_d; 7 | }; 8 | 9 | S create() { 10 | return S{}; 11 | } 12 | 13 | int main() { 14 | auto [f, s] = std::make_tuple(1, 1.5); 15 | std::cout << "f = " << f << '\n'; 16 | std::cout << "s = " << s; 17 | 18 | auto const & [i, d] = create(); 19 | } 20 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws04/04_00_copy_demo/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct CopyableThing { 4 | CopyableThing() { 5 | std::cout << "Create Thing\n"; 6 | } 7 | CopyableThing(CopyableThing const &) { 8 | std::cout << "Copy Thing\n"; 9 | } 10 | }; 11 | 12 | CopyableThing create() { 13 | CopyableThing t{}; 14 | return t; 15 | } 16 | 17 | int main() { 18 | CopyableThing created = create(); 19 | } 20 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws12/UniversalOpaquePointerDemo/src/UniversalOpaquePointerDemo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | template 5 | void *makeOpaque(T *ptr){ 6 | return ptr; 7 | } 8 | 9 | template 10 | T *ptrCast(void *p){ 11 | return static_cast(p); 12 | } 13 | 14 | 15 | int main() { 16 | int i{42}; 17 | void * const pi{makeOpaque(&i)}; 18 | cout << *ptrCast(pi)<< endl; 19 | } 20 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/FizzBuzzVariadicClassSingleDigit/FizzBuzzVariadicClassSingleDigit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws04/04_01_move_demo/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct MoveableThing { 4 | MoveableThing() { 5 | std::cout << "Create Thing\n"; 6 | } 7 | 8 | MoveableThing(MoveableThing &&) { 9 | std::cout << "Move Thing\n"; 10 | } 11 | }; 12 | 13 | MoveableThing create() { 14 | MoveableThing t{}; 15 | return t; 16 | } 17 | 18 | int main() { 19 | MoveableThing created = create(); 20 | } 21 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws14/addable/addable.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "addable_sum.h" 5 | 6 | /*auto add2(Addable a, Addable b){ 7 | return a+b; 8 | }*/ // internal compiler error 9 | int main(){ 10 | std::vector v(20); 11 | iota(v.begin(),v.end(),1); 12 | std::cout << sum(v.begin(),v.end(),0) << '\n'; 13 | std::cout << add(5,37.0) << '\n'; 14 | std::cout << add1(5,37) << '\n'; 15 | } 16 | -------------------------------------------------------------------------------- /ws02/charcount_for_eof_demo/README.md: -------------------------------------------------------------------------------- 1 | This small example shows how to read characters from standard input. 2 | 3 | It can be used as a template for the exercises. 4 | But later in the semester you will learn other ways to perform the operation 5 | in more flexible or robust ways. 6 | 7 | **CAUTION**: Do not run this program within the Eclipse Console on Linux or MacOSX, 8 | because there the EOF-handling (CTRL-D) is broken. Run it in a separate Terminal 9 | instead. -------------------------------------------------------------------------------- /ws10/minwithouttemplate/MyMin.h: -------------------------------------------------------------------------------- 1 | #ifndef MYMIN_H_ 2 | #define MYMIN_H_ 3 | namespace MyMin{ 4 | inline int min(int a, int b){ 5 | return (a < b)? a : b ; 6 | } 7 | inline double min(double a, double b){ 8 | return (a < b)? a : b ; 9 | } 10 | } 11 | #include 12 | namespace MyMin { 13 | inline std::string const &min(std::string const & a, std::string const & b){ 14 | return (a < b)? a : b ; 15 | } 16 | } 17 | #endif /*MYMIN_H_*/ 18 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws14/lessthan/lessthan.cpp: -------------------------------------------------------------------------------- 1 | #include "lessthan.h" 2 | 3 | template 4 | T const &min(T const &a, T const &b){ 5 | return (a 9 | requires LessThanComparable() 10 | T const &max(T const &a, T const &b){ 11 | return (a < b)?b:a; 12 | } 13 | struct X{}; 14 | void operator<(X,X){} 15 | int main(){ 16 | min(3,4); 17 | max(5.0,6.0); 18 | //min(X{},X{}); // concept check fails 19 | } 20 | -------------------------------------------------------------------------------- /exws14/polymorphism/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Inheritance.h" 2 | 3 | int main() { 4 | cout << "a ------\n"; 5 | forum_troll ft { }; 6 | troll t { ft }; 7 | monster &m { ft }; 8 | cout << "b ------\n"; 9 | ft.attack(); 10 | t.attack(); 11 | m.attack(); 12 | cout << "c ------\n"; 13 | ft.swing_club(); 14 | t.swing_club(); 15 | cout << "d ------\n"; 16 | ft.health(); 17 | t.health(); 18 | m.health(); 19 | cout << "end ------\n"; 20 | } 21 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/Triangle.h: -------------------------------------------------------------------------------- 1 | #ifndef TRIANGLE_H_ 2 | #define TRIANGLE_H_ 3 | 4 | #include "Shape.h" 5 | #include 6 | class Triangle: public Shape { 7 | double a,b,c; // represent 3 sides 8 | public: 9 | Triangle(double side1,double side2, double side3); 10 | Triangle(std::istream &in); 11 | unsigned int pegs() const; 12 | double rope() const; 13 | double seeds() const; 14 | std::string name() const; 15 | }; 16 | 17 | #endif /* TRIANGLE_H_ */ 18 | -------------------------------------------------------------------------------- /solws09/wlist_ascending/wlist.cpp: -------------------------------------------------------------------------------- 1 | #include "word.h" //use your word.h Header 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(){ 9 | using in = std::istream_iterator; 10 | 11 | std::set> wlist{in{std::cin}, in{}}; 12 | copy(begin(wlist),end(wlist), 13 | std::ostream_iterator{std::cout, "\n"}); 14 | 15 | } 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws04/04_02_elision/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct Thing { 4 | Thing() { 5 | std::cout << "Create Thing\n"; 6 | } 7 | 8 | Thing(Thing const &) { 9 | std::cout << "Copy Thing\n"; 10 | } 11 | 12 | Thing(Thing &&) { 13 | std::cout << "Move Thing\n"; 14 | } 15 | }; 16 | 17 | Thing create() { 18 | Thing t{}; 19 | return t; 20 | } 21 | 22 | int main() { 23 | Thing created = create(); 24 | } 25 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/Diamond.h: -------------------------------------------------------------------------------- 1 | #ifndef DIAMOND_H_ 2 | #define DIAMOND_H_ 3 | 4 | #include "Shape.h" 5 | #include 6 | class Diamond: public Shape { 7 | double a,b; 8 | double angleInRadian; 9 | public: 10 | Diamond(double side1, double side2, double angleInDegrees); 11 | Diamond(std::istream&); 12 | unsigned int pegs() const; 13 | double rope() const; 14 | double seeds() const; 15 | std::string name() const; 16 | }; 17 | 18 | #endif /* DIAMOND_H_ */ 19 | -------------------------------------------------------------------------------- /ws11/SackScrabble/sackscrabble.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Sack.h" 3 | #include 4 | 5 | int main(){ 6 | Sack scrabble{}; 7 | for (char c='A'; c <= 'Z'; ++c) 8 | scrabble.putInto(c); 9 | std::vector values{scrabble}; 10 | copy(values.begin(),values.end(),std::ostream_iterator{std::cout,"; "}); 11 | std::cout << '\n'; 12 | while (!scrabble.empty()){ 13 | std::cout << "play letter: " << scrabble.getOut() << '\n'; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws02/02_02_auto_specifier/auto_specifier.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template 4 | void assert_same_type(T const &, U const &) { 5 | static_assert(std::is_same_v); 6 | } 7 | 8 | int main() { 9 | int int_value = 1; 10 | auto auto_value = 2; 11 | assert_same_type(int_value, auto_value); 12 | 13 | int another_int{3}; 14 | auto whats_my_type{4}; 15 | assert_same_type(another_int, whats_my_type); 16 | } 17 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/Fibo_CPP03/src/Fibo.h: -------------------------------------------------------------------------------- 1 | #ifndef SRC_FIBO_H_ 2 | #define SRC_FIBO_H_ 3 | 4 | template 5 | struct Fibo { 6 | static_assert(n>=2,"Fibo must be called with a positive number"); 7 | static int const value=Fibo::value+Fibo::value; 8 | }; 9 | 10 | template<> 11 | struct Fibo<0> { 12 | static int const value=0; 13 | }; 14 | template<> 15 | struct Fibo<1> { 16 | static int const value=1; 17 | }; 18 | 19 | 20 | #endif /* SRC_FIBO_H_ */ 21 | -------------------------------------------------------------------------------- /solws06/SimulatedToggleButtonWithTest/src/Switch.h: -------------------------------------------------------------------------------- 1 | #ifndef SWITCH_H_ 2 | #define SWITCH_H_ 3 | #include 4 | class Switch { 5 | public: 6 | Switch(); 7 | void PushButton() ; 8 | void print(std::ostream &) const; 9 | private: 10 | enum class togglestate:unsigned char; 11 | togglestate state; 12 | }; 13 | 14 | inline 15 | std::ostream & operator<<(std::ostream& out,Switch const &s){ 16 | s.print(out); 17 | return out; 18 | } 19 | 20 | 21 | #endif /* SWITCH_H_ */ 22 | -------------------------------------------------------------------------------- /ws03/tolower/README.md: -------------------------------------------------------------------------------- 1 | *tolower.cpp* demonstrates looping over a stream's total input by characters using the unformatted I/O member functions `get(char)` and `put(char)`. 2 | It also shows the `` character conversion function `tolower`. 3 | 4 | *CAUTION* Do not run this within the Cevelop Console on non-Windows operating systems, 5 | unless you have a very recent version of Cevelop, because 6 | Eclipse has a bug with the EOF (Ctrl-D) handling in its console that only got fixed recently. -------------------------------------------------------------------------------- /ws10/demo_variadic/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void printCommaSeparated(std::ostream& out){out << '\n';} // base case 4 | 5 | template 6 | void printCommaSeparated(std::ostream &out,HEAD const &head, TAIL const &... tail){ 7 | out << head; 8 | if (sizeof...(tail)) 9 | out << ", "; 10 | printCommaSeparated(out,tail...); 11 | } 12 | int main() { 13 | printCommaSeparated(std::cout,"A simple demo ", 0x0f, "typesaf",'e',"output"); 14 | } 15 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/FizzBuzzVariadicClassSingleDigit/FizzBuzzVariadicClass.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ws02/greeting/greeting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void askForName(std::ostream &out){ 4 | out << "What is your name? "; 5 | } 6 | std::string inputName(std::istream &in){ 7 | std::string name{}; 8 | in >> name; 9 | return name; 10 | } 11 | void sayGreeting(std::ostream &out,std::string name){ 12 | out << "Hello " << name << ", how are you?\n"; 13 | } 14 | int main() { 15 | askForName(std::cout); 16 | sayGreeting(std::cout, inputName(std::cin)); 17 | } 18 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws01/00_02_IssuesInCevelop/cpp17problems.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std::string_literals; 6 | 7 | template 8 | void printPair(std::ostream & out, std::pair const & p) { 9 | auto [f, s] = p; 10 | out << "first: " << f << " second: " << s; 11 | } 12 | 13 | int main() { 14 | std::pair p = std::make_pair(42, "answer"s); 15 | printPair(std::cout, p); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/FizzBuzzVariadicClass/FizzBuzzVariadicClass.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ws10/variadiclambda/variadiclambda.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | testvariadiclambdawithint: 70 == multby(7) expected: 70 but was: 7 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws12_values_empty_etc/EmptyClasses/EmptyClasses.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /solws13/GardeningLib/Shapes/Shape.cpp: -------------------------------------------------------------------------------- 1 | #include "Shape.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace Gardening; 8 | 9 | double const Shape::seedPerSquareMeter { 0.1 }; 10 | double const Shape::pi { std::atan(1) * 4 }; 11 | 12 | Shape::Shape(std::string const & name) 13 | : name(name){ 14 | } 15 | 16 | void Shape::print(std::ostream & out) const { 17 | out << name << " " << pegs() << " " << ropes() << " " << seeds(); 18 | } 19 | -------------------------------------------------------------------------------- /ws12/biblicalfamily3/README.md: -------------------------------------------------------------------------------- 1 | This directory contains code demonstrating using shared_ptr 2 | for implementing object relationships. 3 | 4 | This is the third step, showing the suboptimal use of shared_ptr for 5 | cyclic relationships. Specific code needs to be called to break the 6 | cycles when one want to get rid of an object. 7 | 8 | NB: there are three more versions demonstrating modifications 9 | when cyclic relationships, e.g., between parents and children 10 | in a family, are represented. -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/SimpleThisThreadExample/src/SimpleThisThreadExample.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | using std::cout; 6 | using std::endl; 7 | using namespace std::this_thread; 8 | using namespace std::chrono_literals; 9 | 10 | std::thread t{[]{ 11 | yield();sleep_for(10ms); 12 | cout << "Hello Thread "<< 13 | get_id()<< endl; 14 | }}; 15 | cout << "Hello Main Thread " << get_id() << endl; 16 | sleep_for(1000ms); 17 | t.join(); 18 | } 19 | -------------------------------------------------------------------------------- /solws04/countingToLower/countingToLower.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/Fibo_CPP03/Fibo_CPP03.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/SimpleThreadDetach/src/SimpleThreadDetach.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | using namespace std::chrono_literals; 8 | using std::cout; 9 | using std::endl; 10 | using namespace std::this_thread; 11 | 12 | std::thread{[]{ 13 | sleep_for(30us); 14 | write(1, "Hello Thread\n",13);} 15 | // should not use cout, it might have gone when called 16 | }.detach(); 17 | cout << "Hello Main" << endl; 18 | } 19 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws14/unary_concept/unary_concept.cpp: -------------------------------------------------------------------------------- 1 | template 2 | concept bool Addable(){ 3 | return requires(ADD a, ADD b){ 4 | {a+b}->ADD; 5 | }; 6 | } 7 | 8 | template 9 | struct Twice { 10 | auto operator()(A a) { 11 | return a+a; 12 | } 13 | }; 14 | 15 | auto twice(Addable a) { 16 | return a+a; 17 | } 18 | 19 | int main(){ 20 | struct X{}; 21 | // Twice tryit; 22 | // tryit(X{}); 23 | Twice works; 24 | works(42); 25 | twice(42); 26 | } 27 | -------------------------------------------------------------------------------- /ws08/demorotate/rotate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | void show(std::vector const &v, std::ostream& os) { 6 | std::ostream_iterator out(os,", "); 7 | copy(cbegin(v), cend(v), out); 8 | os << '\n'; 9 | } 10 | int main(){ 11 | std::vector v{3,1,4,1,5,9,2,6}; 12 | using std::cout; 13 | show(v, cout); 14 | std::rotate(begin(v),begin(v)+3,end(v)); 15 | show(v, cout); 16 | std::reverse(begin(v),end(v)); 17 | show(v, cout); 18 | } 19 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws09/ExplosiveLiquid/random.h: -------------------------------------------------------------------------------- 1 | #ifndef RANDOM_H_ 2 | #define RANDOM_H_ 3 | 4 | 5 | #include 6 | 7 | template 8 | struct PercentageRandomProvider { 9 | 10 | auto operator()() const { 11 | std::uniform_int_distribution uniform_dist(0, 100); 12 | return uniform_dist(rng); 13 | } 14 | private: 15 | mutable RandomDeviceType rng{}; 16 | }; 17 | 18 | 19 | 20 | #endif /* RANDOM_H_ */ 21 | -------------------------------------------------------------------------------- /solws10/squares_solution/src/squares.cpp: -------------------------------------------------------------------------------- 1 | #include "squares.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | std::vector fill_with_squares() { 10 | std::vector squares(10, 1); 11 | 12 | std::partial_sum(std::begin(squares), std::end(squares), std::begin(squares)); 13 | std::transform(std::begin(squares), std::end(squares), std::begin(squares), std::begin(squares), std::multiplies<>{}); 14 | 15 | return squares; 16 | } 17 | -------------------------------------------------------------------------------- /solws13/GardeningLib/Shapes/Circle.h: -------------------------------------------------------------------------------- 1 | #ifndef CIRCLE_H_ 2 | #define CIRCLE_H_ 3 | 4 | #include "Shape.h" 5 | #include 6 | 7 | namespace Gardening { 8 | 9 | struct Circle : Shape { 10 | static unsigned const requiredPegs; 11 | static std::string const name; 12 | 13 | explicit Circle(double radius); 14 | 15 | unsigned pegs() const; 16 | double ropes() const; 17 | double seeds() const; 18 | 19 | private: 20 | double const radius; 21 | }; 22 | 23 | } 24 | 25 | #endif /* CIRCLE_H_ */ 26 | -------------------------------------------------------------------------------- /ws02/typeinfo_for_literals/README.md: -------------------------------------------------------------------------------- 1 | This program will give the answers to the interactive lecture 2 | by printing the types of literals and its value. 3 | 4 | **NB:** It uses GCC-specific compiler intrinsics to provide a user-readable 5 | typename, i.e., the `typeinfo::name()` function would return "i" for an "int", as 6 | defined in the Itanium ABI used by this compiler. It also works with Clang, since 7 | it uses the same ABI and API. The MS C++ compiler will provide a user-readable 8 | typename string by just calling `typeinfo::name()` -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws02/02_10_string_view/string_view.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | //bool contains(std::string const & str, std::string const & substr) { 6 | // return str.find(substr) != std::string::npos; 7 | //} 8 | 9 | bool contains(std::string_view str, std::string_view substr) { 10 | return str.find(substr) != std::string::npos; 11 | } 12 | 13 | 14 | int main() { 15 | std::string s{"it is where you look last"}; 16 | std::cout << std::boolalpha << contains(s, "last"); 17 | } 18 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/07_02_extract_middle/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | template 6 | decltype(auto) extractMiddleElement(Container & container) { 7 | typename Container::value_type nthElement{}; 8 | std::swap(container.at(container.size() / 2), nthElement); 9 | return nthElement; 10 | } 11 | 12 | 13 | int main(int argc, char **argv) { 14 | std::array values { 1, 2, 3 }; 15 | std::cout << "Middle Element: " << extractMiddleElement(values) << '\n'; 16 | } 17 | -------------------------------------------------------------------------------- /CppAdvanced/other/user_defined_literals_ambiguity_s/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char **argv) { 7 | using namespace std::string_literals; 8 | using namespace std::chrono_literals; 9 | auto one_s = 1s; 10 | auto one_point_zero_s = 1.0s; 11 | auto fourty_two_s = "42"s; 12 | std::cout << typeid(one_s).name() << '\n'; 13 | std::cout << typeid(one_point_zero_s).name() << '\n'; 14 | std::cout << typeid(fourty_two_s).name() << '\n'; 15 | } 16 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/Shape.h: -------------------------------------------------------------------------------- 1 | #ifndef SHAPE_H_ 2 | #define SHAPE_H_ 3 | #include 4 | #include 5 | class Shape { 6 | public: 7 | Shape()=default; 8 | virtual ~Shape()=default; 9 | virtual unsigned int pegs() const=0; 10 | virtual double rope() const=0; 11 | virtual double seeds() const=0; 12 | virtual std::string name() const =0; 13 | void print(std::ostream &os)const; 14 | }; 15 | inline std::ostream &operator<<(std::ostream &os,Shape const &s){ 16 | s.print(os); 17 | return os; 18 | } 19 | 20 | #endif /* SHAPE_H_ */ 21 | -------------------------------------------------------------------------------- /ws03/copycat/README.md: -------------------------------------------------------------------------------- 1 | This example demonstrates the use of the `istreambuf_iterator` and `ostream_iterator` types 2 | for reading and writing standard output. Since `istreambuf_iterator` uses the `get(char)` member function 3 | of `std::istream` it will read all characters and not skip whitespace on input. 4 | 5 | *CAUTION* Do not run this within the Cevelop Console on non-Windows operating systems, 6 | unless you have a very recent version of Cevelop, because 7 | Eclipse has a bug with the EOF (Ctrl-D) handling in its console that only got fixed recently. -------------------------------------------------------------------------------- /ws01/helloworld/helloworld.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // Name : helloworld.cpp 3 | // Author : Peter Sommerlad 4 | // Version : 5 | // Copyright : IFS Institute for Software 6 | // Description : Hello World in C++, Ansi-style 7 | //============================================================================ 8 | 9 | #include 10 | using namespace std; 11 | 12 | int main() { 13 | cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!! 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/07_03_arbitrary_printer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void printAll() { 5 | } 6 | 7 | template 8 | void printAll(First const & first, Types const &...rest) { 9 | std::cout << first; 10 | if (sizeof...(Types)) { 11 | std::cout << ", "; 12 | } 13 | printAll(rest...); 14 | } 15 | 16 | 17 | int main(int argc, char **argv) { 18 | int i { 42 }; 19 | double d { 1.25 }; 20 | std::string book { "Lucid C++" }; 21 | printAll(i, d, book); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /solws06/SimulatedToggleButtonWithTest/src/Switch.cpp: -------------------------------------------------------------------------------- 1 | #include "Switch.h" 2 | #include 3 | enum class Switch::togglestate:unsigned char{ 4 | off, on, blink 5 | }; 6 | 7 | Switch::Switch() :state{togglestate::off}{ 8 | } 9 | 10 | void Switch::PushButton() { 11 | state = togglestate((int(state)+1)%3); 12 | } 13 | 14 | void Switch::print(std::ostream& out) const{ 15 | switch(state){ 16 | case togglestate::off: out << "off"; break; 17 | case togglestate::on: out << "on"; break; 18 | case togglestate::blink:out << "blink"; break; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /solws13/echor/echor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char const *argv[]) { 7 | std::vector const v(argv + 1, argv + argc); 8 | copy(std::rbegin(v), std::rend(v), std::ostream_iterator { std::cout, " " }); 9 | std::cout << '\n'; 10 | // without extra copying: 11 | copy(std::make_reverse_iterator(argv + argc), std::make_reverse_iterator(argv + 1), 12 | std::ostream_iterator { std::cout, " " }); 13 | std::cout << '\n'; 14 | } 15 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_sol_ws02/SolEx02_03_FoldRead/SolEx02_03_FoldRead.exe.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11b_MI/MI_StrangersAndFriends/MI_StrangersAndFriends.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | class Appenzeller { 6 | std::string geheimrezept; 7 | friend void ChristophHollenstein(Appenzeller const & app); 8 | }; 9 | 10 | void ChristophHollenstein(Appenzeller const & app) { 11 | std::cout << app.geheimrezept << std::endl; 12 | } 13 | 14 | void UweOchsenknecht(Appenzeller const & app) { 15 | std::cout << app.geheimrezept << std::endl; 16 | } 17 | 18 | int main(int argc, char **argv) { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /CppAdvanced/other/user_defined_literals_string/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace mystring { 4 | std::string operator"" _s(char const *s, std::size_t len) { 5 | return std::string { s, len }; 6 | } 7 | std::string operator"" _s(char const *s) { 8 | return std::string { s }; 9 | } 10 | 11 | } 12 | 13 | 14 | int main(int argc, char **argv) { 15 | using namespace mystring; 16 | auto s = "hello"_s; 17 | s += " world\n"; 18 | std::cout << s; 19 | 20 | auto rs = 42_s; 21 | rs += " raw\n"; 22 | std::cout << rs; 23 | } 24 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws02/02_03_any_lecture_example/any.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void any_example(std::ostream & out) { 5 | std::any value{}; 6 | out << "has value? " << value.has_value() << '\n'; 7 | value = 5; 8 | out << std::any_cast(value) << '\n'; 9 | try { 10 | std::any_cast(value); 11 | } catch(std::bad_any_cast const &) { 12 | out << "std::bad_any_cast thrown, " 13 | "when accessing int as long!\n"; 14 | } 15 | } 16 | 17 | int main() { 18 | any_example(std::cout); 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/fac_from_integral_constant/fac_from_integral_constant.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | template 5 | constexpr auto faci(INT i){ 6 | INT res=1; 7 | while( i>0) 8 | res*=i--; 9 | return res; 10 | } 11 | 12 | template 13 | constexpr auto facic(std::integral_constant){ 14 | return std::integral_constant{}; 15 | } 16 | 17 | constexpr auto val=facic(std::integral_constant{}); 18 | 19 | int main(){ 20 | std::cout << val.value; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /solws13/GardeningLib/Shapes/Square.h: -------------------------------------------------------------------------------- 1 | #ifndef SQUARE_H_ 2 | #define SQUARE_H_ 3 | 4 | #include "Shape.h" 5 | #include 6 | 7 | namespace Gardening { 8 | 9 | struct Square : Shape { 10 | static unsigned const requiredPegs; 11 | static unsigned const numberOfSides; 12 | static std::string const name; 13 | 14 | explicit Square(double side); 15 | 16 | unsigned pegs() const; 17 | double ropes() const; 18 | double seeds() const; 19 | 20 | private: 21 | double const side; 22 | }; 23 | 24 | } 25 | 26 | #endif /* SQUARE_H_ */ 27 | -------------------------------------------------------------------------------- /ws08/multisetexample/sortedlistofwords.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(){ 5 | using in=std::istream_iterator; 6 | using out=std::ostream_iterator; 7 | std::multiset words{in{std::cin},in{}}; 8 | copy(words.begin(),words.end(),out(std::cout,"\n")); 9 | auto bw=words.begin(); 10 | while(bw!=words.end()){ 11 | auto ew=words.upper_bound(*bw); // end of range 12 | copy(bw,ew,out{std::cout,", "}); 13 | std::cout << '\n'; // next range on new line 14 | bw=ew; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws03/copy_and_move_semantics_example/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // (c) by Nicolai Josuttis, used with permission 5 | 6 | std::vector createAndInsert() { 7 | std::vector < std::string > coll; 8 | coll.reserve(3); 9 | std::string s("data"); 10 | 11 | coll.push_back(s); 12 | 13 | coll.push_back(s + s); 14 | 15 | coll.push_back(s); 16 | 17 | return coll; 18 | } 19 | 20 | int main(int argc, char **argv) { 21 | std::vector v; 22 | v = createAndInsert(); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /exws14/BedShapesTest/src/Rectangle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Rectangle.h 3 | * 4 | * Created on: Apr 30, 2010 5 | * Author: sop 6 | */ 7 | 8 | #ifndef RECTANGLE_H_ 9 | #define RECTANGLE_H_ 10 | 11 | #include "Square.h" 12 | #include 13 | 14 | class Rectangle: public Shape { 15 | double length; 16 | double width; 17 | public: 18 | Rectangle(double len, double wid); 19 | Rectangle(std::istream &); 20 | unsigned int pegs() const; 21 | double rope() const; 22 | double seeds() const; 23 | std::string name() const; 24 | }; 25 | 26 | #endif /* RECTANGLE_H_ */ 27 | -------------------------------------------------------------------------------- /solws13/GardeningLib/Shapes/Rectangle.h: -------------------------------------------------------------------------------- 1 | #ifndef RECTANGLE_H_ 2 | #define RECTANGLE_H_ 3 | 4 | #include "Shape.h" 5 | #include 6 | 7 | namespace Gardening { 8 | 9 | struct Rectangle : Shape { 10 | static unsigned const requiredPegs; 11 | static std::string const name; 12 | 13 | Rectangle(double sideA, double sideB); 14 | 15 | unsigned pegs() const; 16 | double ropes() const; 17 | double seeds() const; 18 | 19 | private: 20 | double const sideA; 21 | double const sideB; 22 | }; 23 | 24 | } 25 | 26 | #endif /* RECTANGLE_H_ */ 27 | -------------------------------------------------------------------------------- /ws03/cat/README.md: -------------------------------------------------------------------------------- 1 | This example demonstrates the use of the `istream_iterator` and `ostream_iterator` types 2 | for reading and writing standard output. Please note that those are using `operator>>` and `operator<<` 3 | respectively for reading and writing values, so that contiguous whitespace gets compressed to a single blank on 4 | output. 5 | 6 | *CAUTION* Do not run this within the Cevelop Console on non-Windows operating systems, 7 | unless you have a very recent version of Cevelop, because 8 | Eclipse has a bug with the EOF (Ctrl-D) handling in its console that only got fixed recently. -------------------------------------------------------------------------------- /ws05/RingModulo5Constexpr/README.md: -------------------------------------------------------------------------------- 1 | This example library demonstrates operator overloading in a way, 2 | so that the class becomes a "Literal Type" and is usable for compile-time computations. 3 | 4 | Note the use of operator overloading and constexpr. 5 | 6 | Because Boost.operators are not (yet) constexpr compatible, 7 | the code is incomplete wrt to the defined operators. 8 | 9 | Completion to include full set of arithmetic and relational operators is left as an exercise. 10 | 11 | Test cases should be extended using static_assert to really check for compile-time computation. -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws02/02_07_path_example/path.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace fs = std::experimental::filesystem; 5 | 6 | int main() { 7 | using std::cout; 8 | fs::path const p{"./Hallo"}; 9 | cout << p << '\n'; 10 | if (is_directory(p)) { 11 | cout << " DIR exists" << '\n'; 12 | fs::remove(p); 13 | } else { 14 | cout << "creating dir " << p ; 15 | if (fs::create_directory(p)) 16 | cout << " success"; 17 | else 18 | cout << " failed"; 19 | cout << '\n'; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws03/copy_move_constructors/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct S { 5 | S() { 6 | std::cout << "creating S\n"; 7 | } 8 | 9 | S(S const &) { 10 | std::cout << "copying S\n"; 11 | } 12 | 13 | S(S&&) { 14 | std::cout << "moving S\n"; 15 | } 16 | }; 17 | 18 | 19 | int main() { 20 | std::cout << "\t --- S s{} ---\n"; 21 | S s{}; 22 | 23 | std::cout << "\t --- S copy{s} ---\n"; 24 | S copy{s}; 25 | 26 | std::cout << "\t --- S move{std::move(s)} ---\n"; 27 | S move{std::move(s)}; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws06/emplace/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | struct Point { 7 | Point(int x, int y) : 8 | x { x }, y { y } { 9 | std::cout << "creating Point{" << x << ", " << y << "}\n"; 10 | } 11 | int const x, y; 12 | ~Point() { 13 | std::cout << "destroying Point{" << x << ", " << y << "}\n"; 14 | } 15 | Point(Point const &) = delete; 16 | Point(Point&&) = delete; 17 | }; 18 | 19 | int main(int argc, char **argv) { 20 | std::stack pointStack{}; 21 | pointStack.emplace(1, 2); 22 | } 23 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws13/DemoPathWithUnicode/src/DemoPathWithUnicode.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | namespace fs=std::experimental::filesystem; 5 | 6 | int main(int argc, char **argv) { 7 | fs::path p{u8"./H\u00e4ll\u00f6"}; 8 | cout << p << '\n'; 9 | if (is_directory(p)){ 10 | cout << " DIR exists" << '\n'; 11 | fs::remove(p); 12 | }else{ 13 | cout << "creating dir "<

2 | #include 3 | constexpr int fac(int i) { 4 | if (i > 0) 5 | return i * fac(i - 1); 6 | else if (i == 0) 7 | return 1; 8 | else 9 | throw std::invalid_argument{"negative"}; 10 | } 11 | 12 | int main(){ 13 | char s[fac(6)]; // check compile time execution 14 | std::cout << "sizeof s = "<< sizeof(s); 15 | fac(-1); // run-time error 16 | //constexpr auto val=fac(-2); // compile time error 17 | //constexpr auto val1=fac(13); // overflow-> compile time error 18 | } 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/FizzBuzzVariadicClassComplete/FizzBuzzVariadicClassComplete.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /solws13/GardeningLib/Shapes/Ellipse.h: -------------------------------------------------------------------------------- 1 | #ifndef ELLIPSE_H_ 2 | #define ELLIPSE_H_ 3 | 4 | #include "Shape.h" 5 | #include 6 | 7 | namespace Gardening { 8 | 9 | struct Ellipse : Shape { 10 | static unsigned const requiredPegs; 11 | static std::string const name; 12 | 13 | Ellipse(double semiMajorAxis, double semiMinorAxis); 14 | 15 | unsigned pegs() const; 16 | double ropes() const; 17 | double seeds() const; 18 | 19 | private: 20 | double const semiMajorAxis; 21 | double const semiMinorAxis; 22 | }; 23 | 24 | } 25 | 26 | #endif /* ELLIPSE_H_ */ 27 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws14/addable_member/addable_member.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "addable_sum.h" 5 | 6 | template 7 | struct Vec : std::vector { 8 | using std::vector::vector; 9 | auto sum() const ->T requires Addable() { 10 | T res{}; 11 | for(auto x:*this){ res = res + x ; } 12 | return res; 13 | } 14 | }; 15 | int main(){ 16 | Vec v(20); 17 | std::iota(v.begin(),v.end(),1); 18 | std::cout << sum(v.begin(),v.end(),0) << '\n'; 19 | std::cout << add(5,37.0) << '\n'; 20 | std::cout << v.sum() << '\n'; 21 | } 22 | -------------------------------------------------------------------------------- /ws04/chapter_function_syntax/factorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | int factorial(int n){ 11 | if (n > 1) return n * factorial(n-1); 12 | return 1; 13 | } 14 | double factorial(double n) { 15 | double result=1; 16 | if (n < 15) 17 | return factorial(int(n)); 18 | while(n > 1) { 19 | result *= n; 20 | --n; 21 | } 22 | return result; 23 | } 24 | void demoAmbiguity() { 25 | /* 26 | factorial(10u); // ambiguous 27 | factorial(1e1l);// ambiguous 28 | */ 29 | std::cout << factorial(3) << "\n"; 30 | std::cout << factorial(1e2) << "\n"; 31 | } 32 | -------------------------------------------------------------------------------- /ws11/SafeVector/SafeVector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ws08/stack_and_queue_example/stackqueue.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main(){ 5 | std::stack lifo; 6 | std::queue fifo; 7 | for(std::string s 8 | :{"Fall","leaves","after","leaves","fall"}){ 9 | lifo.push(s); 10 | fifo.push(s); 11 | } 12 | while (!lifo.empty()){ 13 | std::cout << lifo.top() << " "; 14 | lifo.pop(); 15 | } // fall leaves after leaves Fall 16 | std::cout << "\n"; 17 | while (!fifo.empty()){ 18 | std::cout << fifo.front() << " "; 19 | fifo.pop(); 20 | } // Fall leaves after leaves fall 21 | } 22 | -------------------------------------------------------------------------------- /solws08/palindrome/palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | bool isPalindrome(std::string const &s){ 8 | return equal(s.begin(),s.end(),s.rbegin(), 9 | [](char l, char r){ 10 | return std::tolower(l)==std::tolower(r); 11 | }); 12 | } 13 | 14 | int main(){ 15 | std::ifstream input{"/usr/share/dict/words"}; 16 | using initer=std::istream_iterator; 17 | std::ostream_iterator out{std::cout,"\n"}; 18 | copy_if(initer{input},initer{},out,isPalindrome); 19 | } 20 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/SimpleThreadDetachDanger/src/SimpleThreadDetachDanger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | // what can go wrong with this code? 6 | void startThread() { 7 | using namespace std::chrono_literals; 8 | std::string local{"local"}; 9 | std::thread t{[&] { 10 | std::this_thread::sleep_for(1s); 11 | std::cout << "local: " << local << std::endl; 12 | }}; 13 | t.detach(); 14 | } 15 | 16 | int main(int argc, char **argv) { 17 | using namespace std::chrono_literals; 18 | startThread(); 19 | std::this_thread::sleep_for(2s); 20 | } 21 | -------------------------------------------------------------------------------- /ws12/biblicalfamily/Person.h: -------------------------------------------------------------------------------- 1 | #ifndef PERSON_H_ 2 | #define PERSON_H_ 3 | #include 4 | #include 5 | #include 6 | #include 7 | using PersonPtr=std::shared_ptr; 8 | 9 | class Person { 10 | std::string name; 11 | std::vector children; 12 | public: 13 | Person(std::string name):name{name}{} 14 | void addChild(PersonPtr child){ 15 | children.push_back(child); 16 | } 17 | void print(std::ostream &) const; 18 | static PersonPtr makePerson(std::string name){ 19 | return std::make_shared(name); 20 | } 21 | }; 22 | 23 | #endif /* PERSON_H_ */ 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | # Cevelop workspace defaults and project files 31 | Debug 32 | Release 33 | .metadata/ 34 | *Test.xml 35 | .*.html 36 | /**/.settings/* 37 | #!language.settings.xml 38 | 39 | 40 | # Mac OS Meta Files 41 | .DS_Store 42 | .Trashes 43 | -------------------------------------------------------------------------------- /ws12/biblicalfamily/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Person.h" 2 | #include 3 | 4 | void addson(std::string name,PersonPtr adam, PersonPtr eva) { 5 | auto son = Person::makePerson(name); 6 | eva->addChild(son); 7 | adam->addChild(son); 8 | } 9 | 10 | int main() { 11 | auto adam=Person::makePerson("Adam"); 12 | adam->print(std::cout); 13 | auto eva=Person::makePerson("Eva"); 14 | eva->print(std::cout); 15 | addson("Cain",adam, eva); 16 | addson("Abel",adam, eva); 17 | addson("Seth",adam, eva); 18 | adam->print(std::cout); 19 | eva->print(std::cout); 20 | // how to have Cain kill Abel? 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/NonTypeTemplateExample/NonTypeTemplate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | template 4 | struct exp{ 5 | T operator()(T const & val) { 6 | T res = val; 7 | for (unsigned int i=1; i < EXP; ++i) 8 | res *= val; 9 | return res; 10 | } 11 | }; 12 | template 13 | struct exp { 14 | T operator()(T const &val){ 15 | return T(1); 16 | } 17 | }; 18 | 19 | 20 | int main(){ 21 | using namespace std; 22 | cout << exp()(4) << endl; 23 | cout <()(10) << endl; 24 | std::array a{}; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /ws10/minwithouttemplate/main.cpp: -------------------------------------------------------------------------------- 1 | #include "MyMin.h" 2 | #include 3 | #include 4 | 5 | int main(){ 6 | using MyMin::min; 7 | using std::cout; 8 | int i = 88; 9 | cout << "min(i,42) = " << min(i,42) << '\n'; 10 | double pi = 3.1415; 11 | double e = 2.7182; 12 | cout << "min(e,pi) = " << min(e,pi) << '\n'; 13 | std::string s1 = "Hallo"; 14 | std::string s2 = "Hallihallo"; 15 | cout << "min(Hallo,Hallihallo) = " << min(s1,s2)<<'\n'; 16 | //min(2,pi); // compile error 17 | min(static_cast(2),pi); 18 | cout << "min(Toni,Peter) = " << min("Toni","Peter") << '\n'; 19 | } 20 | -------------------------------------------------------------------------------- /ws05/enumDemo/Statemachine.cpp: -------------------------------------------------------------------------------- 1 | #include "Statemachine.h" 2 | #include 3 | enum class Statemachine::State: unsigned short { 4 | begin, middle, end 5 | }; 6 | 7 | Statemachine::Statemachine() 8 | :theState{State::begin} {} 9 | 10 | void Statemachine::processInput(char c){ 11 | switch(theState){ 12 | case State::begin : 13 | if (! isspace(c)) 14 | theState=State::middle; 15 | break; 16 | case State::middle : 17 | if (isspace(c)) 18 | theState=State::end; 19 | break; 20 | case State::end : break;// ignore input 21 | } 22 | } 23 | bool Statemachine::isDone()const{ 24 | return theState==State::end; 25 | } 26 | -------------------------------------------------------------------------------- /ws08/squarespartial_sumtransform/squares.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | int main(){ 8 | std::ostream_iterator out{std::cout,", "}; 9 | std::vector v(10,1); 10 | copy(v.begin(),v.end(),out); std::cout << '\n'; 11 | transform(v.begin(),v.end()-1,v.begin()+1,v.begin()+1, std::plus{}); 12 | 13 | //partial_sum(v.begin(),v.end(),v.begin()); 14 | copy(v.begin(),v.end(),out); std::cout << '\n'; 15 | transform(v.begin(),v.end(),v.begin(),out, 16 | std::multiplies{}); 17 | } 18 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11b_MI/MI_MixInInheritance_CRTP/MI_MixInInheritance_CRTP.cpp: -------------------------------------------------------------------------------- 1 | template 2 | struct addable { 3 | friend T operator+(T lhs, T const & rhs) { 4 | return lhs += rhs; 5 | } 6 | }; 7 | 8 | struct Number 9 | // : addable 10 | { 11 | Number(long long value) : 12 | value { value } { 13 | } 14 | 15 | // Number & operator +=(Number const & rhs) { 16 | // value += rhs.value; 17 | // return *this; 18 | // } 19 | 20 | private: 21 | long long value; 22 | }; 23 | 24 | 25 | int main(int argc, char **argv) { 26 | Number n { 15 }; 27 | // n += n; 28 | // n + n; 29 | } 30 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/FizzBuzzVariadic/FizzBuzzVariadic.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ws11/LimitNumberOfInstances/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "cute.h" 2 | #include "ide_listener.h" 3 | #include "cute_runner.h" 4 | #include "LimitNumberOfInstances.h" 5 | class one:LimitNofInstances{ /*...*/}; 6 | void testOnlyOne() { 7 | one theOne; 8 | ASSERT_THROWS(one(),std::logic_error); 9 | ASSERT_THROWS(one(theOne),std::logic_error); 10 | } 11 | 12 | void runSuite(){ 13 | cute::suite s; 14 | //TODO add your test here 15 | s.push_back(CUTE(testOnlyOne)); 16 | cute::ide_listener lis; 17 | cute::makeRunner(lis)(s, "The Suite"); 18 | } 19 | 20 | int main(){ 21 | runSuite(); 22 | } 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /ws10/variadicfunctiontemplate/variadicfunctiontemplate.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | testVariadicPrint: "1, 2, 3, hello, , world\\n" == out.str() expected: 1, 2, 3, hello, , world\n but was: 1, 2, 3, hello, , wrld\n 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws12/WizardPimpl/Wizard.h: -------------------------------------------------------------------------------- 1 | #ifndef WIZARD_H_ 2 | #define WIZARD_H_ 3 | #include 4 | #include 5 | class Wizard { // all magic details hidden 6 | std::unique_ptr const pimpl; 7 | 8 | public: 9 | Wizard(std::string name="Rincewind"); 10 | ~Wizard(); // must declare and define in .cpp 11 | Wizard(Wizard &&)=default; 12 | Wizard& operator=(Wizard&&)=default; 13 | std::string doMagic(std::string const &wish); 14 | void learnSpell(std::string const &newspell); 15 | void mixAndStorePotion(std::string const &potion); 16 | std::string getName() const; 17 | }; 18 | 19 | #endif /* WIZARD_H_ */ 20 | -------------------------------------------------------------------------------- /ws02/bad_greeting/greeting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | void askForName(std::ostream &out){ 4 | out << "What is your name? "; 5 | } 6 | std::string inputName(std::istream &in){ 7 | std::string name{}; 8 | in >> name; 9 | return name; 10 | } 11 | void sayGreeting(std::ostream &out, 12 | std::string name1, 13 | std::string name2){ 14 | out << "Hello " << name1 << ", do you love " 15 | << name2 << "?\n"; 16 | } 17 | int main() { 18 | askForName(std::cout); 19 | sayGreeting(std::cout, inputName(std::cin), 20 | inputName(std::cin)); // order is unspecified 21 | } 22 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/FizzBuzzVariadicNonRecursive/FizzBuzzVariadic.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /solws03/multab/multab.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | std::string to_string_width5(unsigned num) { 8 | std::ostringstream os { }; 9 | os << std::setw(5) << num; 10 | return os.str(); 11 | } 12 | 13 | int main(){ 14 | std::vector v(20); 15 | iota(begin(v),end(v),1); 16 | std::ostream_iterator out{std::cout,""}; 17 | for_each(cbegin(v),cend(v),[=](unsigned row){ 18 | transform(cbegin(v),cend(v),out, 19 | [=](unsigned col){ 20 | return to_string_width5(col* row); 21 | }); 22 | std::cout << '\n'; 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /ws08/democopybackward/copybackward.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | void show(std::vector const &v, std::ostream& os) { 6 | std::ostream_iterator out(os,", "); 7 | copy(cbegin(v), cend(v), out); 8 | os << '\n'; 9 | } 10 | int main(){ 11 | std::vector v{3,1,4,1,5,9,2,6}; 12 | using std::cout; 13 | show(v, cout); 14 | std::copy(cbegin(v)+2,cend(v),begin(v)); 15 | show(v, cout); 16 | std::copy_backward(cbegin(v),cend(v)-2,end(v)); 17 | show(v,cout); 18 | auto middle=begin(v)+(v.size()/2); 19 | std::swap_ranges(begin(v),middle,middle); 20 | show(v,cout); 21 | } 22 | -------------------------------------------------------------------------------- /ws02/how_old_are_you_robust_ignoring/how_old_are_you_robust_ignoring.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int inputAge(std::istream& in) { 5 | while (in.good()) { 6 | int age{-1}; 7 | if (in>>age) 8 | return age; 9 | in.clear(); // remove fail flag 10 | in.ignore(); // ignore invalid character 11 | //in.ignore(std::numeric_limits::max(),'\n'); // whole line 12 | } 13 | return -1; 14 | } 15 | 16 | 17 | int main() { 18 | std::cout << "Enter your age (invalid ignored): " << std::flush; 19 | 20 | std::cout << "\nYou are " << inputAge(std::cin) 21 | << " years old\n"; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /ws04/chapter_function_syntax_lib/long_function.h: -------------------------------------------------------------------------------- 1 | #ifndef LONG_FUNCTION_H_ 2 | #define LONG_FUNCTION_H_ 3 | #include 4 | #include 5 | 6 | 7 | 8 | 9 | 10 | void writeNTimesToStream( std::ostream& file 11 | , std::string content 12 | , size_t n); 13 | 14 | bool writeNTimesToStreamIfOk( std::ostream& file 15 | , std::string content 16 | , size_t n); 17 | 18 | 19 | bool writeNTimesToFile3(std::string filename 20 | , std::string content 21 | , size_t n); 22 | 23 | 24 | 25 | #endif /* LONG_FUNCTION_SYNTAX_H_ */ 26 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/FizzBuzzVariadicNonRecursive/FizzBuzzVariadicNonRecursive.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/fac_prohibit_run_time_call/fac_prohibit_run_time_call.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | constexpr int fac(const int i) { 3 | extern char const * const fac_should_not_be_called_at_run_time; // undefined symbol 4 | if (i > 0) 5 | return i * fac(i - 1); 6 | else if (i == 0) 7 | return 1; 8 | else 9 | throw fac_should_not_be_called_at_run_time; // will raise linker error 10 | } 11 | 12 | 13 | int main(){ 14 | constexpr auto val=fac(3); 15 | const char s[fac(6)] { }; // check compile time execution 16 | std::cout << "sizeof s = "<< sizeof(s); 17 | // fac(-1); // will raise linker error about undefined symbol 18 | } 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws04/04_05_overload_resolution_member_functions/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct S { 5 | // void m() { 6 | // std::cout << "m()\n"; 7 | // } 8 | // void m() const { 9 | // std::cout << "m() const\n"; 10 | // } 11 | void m() & { 12 | std::cout << "m() &\n"; 13 | } 14 | void m() const & { 15 | std::cout << "m() const &\n"; 16 | } 17 | void m() && { 18 | std::cout << "m() &&\n"; 19 | } 20 | }; 21 | 22 | 23 | 24 | int main(int argc, char **argv) { 25 | S s{}; 26 | s.m(); 27 | 28 | S const sc{}; 29 | sc.m(); 30 | 31 | S{}.m(); 32 | 33 | std::move(s).m(); 34 | } 35 | -------------------------------------------------------------------------------- /solws13/GardeningLib/Shapes/Shape.h: -------------------------------------------------------------------------------- 1 | #ifndef SHAPE_H_ 2 | #define SHAPE_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace Gardening { 8 | 9 | struct Shape { 10 | static const double pi; 11 | static const double seedPerSquareMeter; 12 | 13 | virtual ~Shape() = default; 14 | 15 | void print(std::ostream & out) const; 16 | 17 | virtual unsigned pegs() const = 0; 18 | virtual double ropes() const = 0; 19 | virtual double seeds() const = 0; 20 | 21 | protected: 22 | explicit Shape(std::string const & name); 23 | 24 | private: 25 | std::string const name; 26 | }; 27 | 28 | } 29 | 30 | #endif /* SHAPE_H_ */ 31 | -------------------------------------------------------------------------------- /ws02/how_old_are_you_robust/how_old_are_you_robust.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int inputAge(std::istream& in) { 4 | while (in) { 5 | std::string line{}; 6 | getline(in, line); 7 | int age{-1}; 8 | // /* 9 | std::istringstream is{line}; 10 | if (is >> age) 11 | return age; 12 | // */ 13 | // alternative: 14 | /* 15 | try{ 16 | age=std::stoi(line); 17 | return age; 18 | } 19 | catch(...){} 20 | */ 21 | } 22 | return -1; 23 | } 24 | 25 | 26 | int main() { 27 | std::cout << "Enter your age: " << std::flush; 28 | 29 | std::cout << "\nYou are " << inputAge(std::cin) 30 | << " years old\n"; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /ws12/shared_ptr_demo_ostream/sharedPtrDemo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | enum class to { string, file}; 6 | 7 | std::shared_ptr os_factory(to mode){ 8 | if (mode == to::string) 9 | return std::make_shared(); 10 | else 11 | return std::make_shared("hello.txt"); 12 | } 13 | 14 | 15 | int main(){ 16 | auto out = os_factory(to::file); 17 | if (out) (*out) << "hello world\n"; 18 | auto fileout = os_factory(to::string); 19 | if (fileout) (*fileout) << "Hello, world!\n"; 20 | fileout.reset(); // clears shared_ptr, deallocates stream object 21 | } 22 | -------------------------------------------------------------------------------- /solws13/topological_sort/topological_sort.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /solws13/topological_sort_main/main.cpp: -------------------------------------------------------------------------------- 1 | #include "module_sort.h" 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char * argv[]){ 7 | if (argc>1){ 8 | std::ifstream input{argv[1]}; 9 | print_semester_topological(input,std::cout); 10 | } else { 11 | using namespace std::string_literals; 12 | std::istringstream input { 13 | R"( 14 | DB1 OO 15 | DB2 DB1 16 | Math 17 | OO 18 | AD1 OO 19 | CPI OO Math 20 | Thesis DB2 SE2 UI2 21 | SE1 AD1 CPI DB1 22 | SE2 DB1 SE1 UI1 23 | UI1 AD1 24 | UI2 UI1 25 | )"s 26 | }; 27 | print_semester_topological(input,std::cout); 28 | } 29 | } 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /ws04/chapter_function_syntax_move_ctor/factoryfunction.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | std::ofstream fileFactory(std::string filename){ 11 | std::ofstream theFile{filename}; 12 | return theFile; 13 | } 14 | 15 | 16 | 17 | 18 | 19 | 20 | void writeToFile(std::ofstream file){ 21 | file << "hello, world\n"; 22 | } 23 | 24 | 25 | 26 | 27 | 28 | int main(){ 29 | std::ofstream out=fileFactory("hello.txt"); 30 | out << "hello\n"; 31 | writeToFile(std::move(out)); 32 | // cannot use out here anymore 33 | if (out << "more?"){ 34 | std::cout << "oops out should be empty now\n"; 35 | } 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /ws12/demo_unique_ptr_transfer/demo_unique_ptr_transfer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | std::unique_ptr afactory(int i){ 4 | return std::make_unique(i); 5 | } 6 | int main(){ 7 | auto pi=afactory(42); 8 | 9 | std::cout << "*pi =" << *pi << '\n'; 10 | std::cout << "pi.valid? "<< std::boolalpha 11 | << static_cast(pi) << '\n'; 12 | auto pj=std::move(pi); 13 | std::cout << "*pj =" << *pj << '\n'; 14 | std::cout << "pi.valid still? " 15 | << static_cast(pi) << '\n'; 16 | std::cout << "pj.valid still? " 17 | << static_cast(pj) << '\n'; 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_sol_ws02/SolEx02_03_FoldRead/src/readln.h: -------------------------------------------------------------------------------- 1 | #ifndef READLN_H_ 2 | #define READLN_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace readln_impl { 9 | 10 | template 11 | void doread(std::istream & in, T &...pack) { 12 | (in >> ... >> pack); 13 | } 14 | 15 | } 16 | 17 | template 18 | void readln(std::istream &in, I&...vars) { 19 | using namespace readln_impl; 20 | std::string line { }; 21 | getline(in, line); 22 | std::istringstream input { line }; 23 | doread(input, vars...); 24 | if (input.fail()) 25 | in.setstate(std::ios::failbit); 26 | } 27 | 28 | #endif /* READLN_H_ */ 29 | -------------------------------------------------------------------------------- /ws09/sortstandardfunctor/sortstandardfunctor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | 9 | 10 | void print(std::vector v, std::ostream& out){ 11 | std::ostream_iterator os{out,", "}; 12 | copy(v.begin(),v.end(),os); 13 | out << '\n'; 14 | } 15 | 16 | 17 | void demosort(std::ostream &out){ 18 | std::vector v{-1,2,-5,3,-4,-2}; 19 | print(v,out); 20 | sort(v.begin(),v.end(),std::greater<>{}); 21 | print(v,out); 22 | } 23 | 24 | 25 | 26 | 27 | int main(){ 28 | demosort(std::cout); 29 | } 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ws10/minwithtemplatesandoverlaodsanddeletedoverloads/MyMin.h: -------------------------------------------------------------------------------- 1 | #ifndef MYMIN_H_ 2 | #define MYMIN_H_ 3 | #include 4 | namespace MyMin{ 5 | #if 0 6 | template 7 | typename std::common_type::type 8 | min(T const& a, U const& b){ 9 | return (a < b)? a : b ; 10 | } 11 | #endif 12 | 13 | template 14 | auto min(T const& a, U const& b)->decltype(a 18 | void min(T * a, U * b)=delete; 19 | 20 | char const * min(char const* a, char const* b); 21 | 22 | } 23 | 24 | #endif /*MYMIN_H_*/ 25 | -------------------------------------------------------------------------------- /solws11/median_solution/src/median.h: -------------------------------------------------------------------------------- 1 | #ifndef MEDIAN_H_ 2 | #define MEDIAN_H_ 3 | 4 | #include 5 | #include 6 | 7 | template 8 | T const &median(T const &a, T const &b, T const &c) { 9 | return std::max(std::min(a, b), std::min(std::max(a, b), c)); 10 | } 11 | 12 | // overload for pointers, don't allow pointers 13 | template 14 | T *median(T *a, T *b, T *c) = delete; 15 | 16 | // overload for string literals 17 | std::string median(char const *ap, char const *bp, char const *cp) { 18 | std::string a { ap }; 19 | std::string b { bp }; 20 | std::string c { cp }; 21 | return median(a, b, c); 22 | } 23 | 24 | #endif /* MEDIAN_H_ */ 25 | -------------------------------------------------------------------------------- /solws13/GardeningLib/Shapes/Diamond.h: -------------------------------------------------------------------------------- 1 | #ifndef DIAMOND_H_ 2 | #define DIAMOND_H_ 3 | 4 | #include "Shape.h" 5 | #include 6 | 7 | namespace Gardening { 8 | 9 | struct Diamond: Shape { 10 | static unsigned const requiredPegs; 11 | static unsigned const numberOfSides; 12 | static std::string const name; 13 | 14 | Diamond(double sideLength, double angleDegrees); 15 | 16 | unsigned pegs() const; 17 | double ropes() const; 18 | double seeds() const; 19 | 20 | private: 21 | double const sideLength; 22 | double const angle; 23 | 24 | static double convertToRad(double degrees); 25 | }; 26 | 27 | } 28 | 29 | #endif /* DIAMOND_H_ */ 30 | -------------------------------------------------------------------------------- /solws13/GardeningLib/Shapes/Triangle.h: -------------------------------------------------------------------------------- 1 | #ifndef TRIANGLE_H_ 2 | #define TRIANGLE_H_ 3 | 4 | #include "Shape.h" 5 | #include 6 | 7 | namespace Gardening { 8 | 9 | struct Triangle : Shape { 10 | static unsigned const requiredPegs; 11 | static std::string const name; 12 | 13 | Triangle(double sideA, double sideB, double sideC); 14 | 15 | unsigned pegs() const; 16 | double ropes() const; 17 | double seeds() const; 18 | 19 | private: 20 | const double sideA; 21 | const double sideB; 22 | const double sideC; 23 | bool checkTriangleInput() const; 24 | double perimeter() const; 25 | }; 26 | 27 | } 28 | 29 | #endif /* TRIANGLE_H_ */ 30 | -------------------------------------------------------------------------------- /solws13/topological_sort_fast/main.cpp: -------------------------------------------------------------------------------- 1 | #include "semester_topological.h" 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char * argv[]){ 7 | if (argc>1){ 8 | std::ifstream input{argv[1]}; 9 | print_semester_topological(input,std::cout); 10 | } else { 11 | using namespace std::string_literals; 12 | std::istringstream input { 13 | R"( 14 | DB1 OO 15 | DB2 DB1 16 | Math 17 | OO 18 | AD1 OO 19 | CPI OO Math 20 | Thesis DB2 SE2 UI2 21 | SE1 AD1 CPI DB1 22 | SE2 DB1 SE1 UI1 23 | UI1 AD1 24 | UI2 UI1 25 | )"s 26 | }; 27 | print_semester_topological(input,std::cout); 28 | } 29 | } 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /ws02/formatted_output/formatted_output.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() { 5 | std::cout << 42 << '\t' 6 | << std::oct << 42 << '\t' 7 | << std::hex << 42 << '\n'; 8 | std::cout << 42 << '\t' // std::hex is sticky 9 | << std::dec << 42 << '\n'; 10 | std::cout << std::setw(10) << 42 11 | << std::left<< std::setw(5)<< 43 << "*\n"; 12 | std::cout << std::setw(10) << "hallo"<<"*\n"; 13 | 14 | double const pi{std::acos(0.5)*3}; 15 | std::cout << std::setprecision(4) << pi << '\n'; 16 | std::cout << std::scientific << pi << '\n'; 17 | std::cout << std::fixed << pi*1e6 << '\n'; 18 | } 19 | -------------------------------------------------------------------------------- /ws12/biblicalfamily4/README.md: -------------------------------------------------------------------------------- 1 | This directory contains code demonstrating using shared_ptr 2 | for implementing object relationships. 3 | 4 | This is the fourth step, showing the use of shared_ptr in 5 | combination with weak_ptr and enable_shared_from_this for 6 | cyclic relationships. This mechanism allows cyclic object 7 | relationships that can be released automatically with the 8 | drawback that one direction is "weak" requiring one to first 9 | check the pointer validity after converting it to a shared_ptr. 10 | 11 | NB: there are three more versions demonstrating modifications 12 | when cyclic relationships, e.g., between parents and children 13 | in a family, are represented. -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws11/Cpp14MultiplicationTableCompileTimeAsString/Cpp14MultiplicationTableCompileTimeAsString.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/Cpp14MultiplicationTableCompileTimeAsString/Cpp14MultiplicationTableCompileTimeAsString.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/FizzBuzzVariadic/src/println.h: -------------------------------------------------------------------------------- 1 | /* 2 | * println.h 3 | * 4 | * Created on: 18.09.2015 5 | * Author: sop 6 | */ 7 | 8 | #ifndef PRINTLN_H_ 9 | #define PRINTLN_H_ 10 | #include 11 | 12 | void println(std::ostream &out) ; 13 | 14 | template 15 | void println(std::ostream &out, Head const& head, Tail const& ...tail) { 16 | out << head; 17 | if (sizeof...(tail)) { 18 | out << ", "; 19 | println(out,tail...); //recurse on tail 20 | } else { 21 | out<< '\n'; 22 | } 23 | } 24 | 25 | inline 26 | void println(std::ostream &out) { 27 | throw "never called"; 28 | } 29 | 30 | 31 | 32 | 33 | #endif /* PRINTLN_H_ */ 34 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws13/DemoDir/src/DemoDir.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | namespace fs=std::experimental::filesystem; 5 | 6 | int main(int argc, char **argv) { 7 | fs::path dir{"./"}; 8 | if (argc >1) 9 | dir=argv[1]; 10 | for (auto p:fs::directory_iterator(dir)){ 11 | cout << p << '\t'; 12 | if (is_directory(p)){ 13 | cout << "DIR"; 14 | }else 15 | try{ 16 | auto sz=fs::file_size(p); // no file sizes for directory 17 | if (sz > 1024) 18 | cout << sz/1024 << " kB"; 19 | else 20 | cout << sz << " Bytes"; 21 | } catch(...){ 22 | cout << "no file size available"; 23 | } 24 | cout << '\n'; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ws10/minwithtemplate/MyMaxTest.cpp: -------------------------------------------------------------------------------- 1 | #include "MyMax.h" 2 | #include 3 | #include 4 | void MyMaxTest(std::ostream &out){ 5 | using MyMax::max; 6 | int i = 88; 7 | out << "max(i,42) = " << max(i,42) << '\n'; 8 | double pi = 3.1415; 9 | double e = 2.7182; 10 | out << "max(e,pi) = " << max(e,pi) << '\n'; 11 | std::string s1 = "Hallo"; 12 | std::string s2 = "Hallihallo"; 13 | out << "max(Hallo,Hallihallo) = " << MyMax::max(s1,s2)<<'\n'; 14 | //max(2,pi); // compile error 15 | max(static_cast(2),pi); 16 | out << "max(Peter,Toni) = " 17 | << max("Peter","Toni") << '\n'; 18 | out << "max(Peter,Toni) = " 19 | << max("Peter","Toni") << '\n'; 20 | } 21 | -------------------------------------------------------------------------------- /ws12/unique_ptr/demouniqueptr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct X{ 5 | X(int i):x{i}{} 6 | int x; 7 | virtual ~X(){std::cout << "X deleted\n";} 8 | }; // a dummy type for demonstration 9 | 10 | struct Y : X { 11 | Y(int i):X{-i},d{3.14}{} 12 | double d; 13 | ~Y(){std::cout << "Y deleted\n";} 14 | }; 15 | 16 | std::unique_ptr factory(int i){ 17 | if (i < 0) 18 | return std::make_unique(i); 19 | return std::make_unique(i); 20 | } 21 | 22 | int main(){ 23 | auto x=factory(42); 24 | std::cout << (*x).x << '\n'; 25 | std::cout << x->x << '\n'; 26 | std::cout << (*x.get()).x << '\n'; 27 | 28 | auto y=factory(-1); 29 | std::cout << (*y).x << '\n'; 30 | } 31 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/FizzBuzzVariadicNonRecursive/src/println.h: -------------------------------------------------------------------------------- 1 | /* 2 | * println.h 3 | * 4 | * Created on: 18.09.2015 5 | * Author: sop 6 | */ 7 | 8 | #ifndef PRINTLN_H_ 9 | #define PRINTLN_H_ 10 | #include 11 | 12 | void println(std::ostream &out) ; 13 | 14 | template 15 | void println(std::ostream &out, Head const& head, Tail const& ...tail) { 16 | out << head; 17 | if (sizeof...(tail)) { 18 | out << ", "; 19 | println(out,tail...); //recurse on tail 20 | } else { 21 | out<< '\n'; 22 | } 23 | } 24 | 25 | inline 26 | void println(std::ostream &out) { 27 | throw "never called"; 28 | } 29 | 30 | 31 | 32 | 33 | #endif /* PRINTLN_H_ */ 34 | -------------------------------------------------------------------------------- /ws09/demomemberpointer/demomemberpointer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | struct X { 5 | void foo(std::ostream &out) const { out << a << " foo\n"; } 6 | void bar(std::ostream &out) const { out << b << " bar\n"; } 7 | int a; 8 | int b; 9 | }; 10 | 11 | void doit(void (X::*mfunc)(std::ostream &) const, X const &x, std::ostream &out){ 12 | (x.*mfunc)(out); // parenthesis needed 13 | } 14 | 15 | void change(int X::*memvar, X& x, int val){ 16 | x.*memvar = val; 17 | } 18 | 19 | 20 | int main(){ 21 | X x{1,2}; 22 | doit(&X::foo,x,std::cout); 23 | doit(&X::bar,x,std::cout); 24 | change(&X::a,x,42); 25 | change(&X::b,x,43); 26 | doit(&X::foo,x,std::cout); 27 | doit(&X::bar,x,std::cout); 28 | } 29 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w6/iteratorboost/intiteratorboost.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | struct intiteratorboost 6 | : boost::input_iterator_helper 7 | { 8 | explicit intiteratorboost(int start=0):value{start}{} 9 | bool operator==(intiteratorboost const &r) const { 10 | return value == r.value; 11 | } 12 | value_type operator*() const { return value; } 13 | intiteratorboost &operator ++() { 14 | ++value; 15 | return *this; 16 | } 17 | private: 18 | int value; 19 | }; 20 | 21 | int main(){ 22 | copy(intiteratorboost{1},intiteratorboost{11}, 23 | std::ostream_iterator{std::cout,", "}); 24 | } 25 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w7/LiteralTypesAndUDL/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "cute.h" 2 | #include "ide_listener.h" 3 | #include "xml_listener.h" 4 | #include "cute_runner.h" 5 | #include "velocity.h" 6 | 7 | 8 | void tupledemo() { 9 | ASSERT_EQUAL(5_km_h, 3_km_h+2_km_h); 10 | } 11 | 12 | void runAllTests(int argc, char const *argv[]){ 13 | cute::suite s; 14 | //TODO add your test here 15 | s.push_back(CUTE(tupledemo)); 16 | cute::xml_file_opener xmlfile(argc,argv); 17 | cute::xml_listener > lis(xmlfile.out); 18 | cute::makeRunner(lis,argc,argv)(s, "AllTests"); 19 | } 20 | 21 | int main(int argc, char const *argv[]){ 22 | runAllTests(argc,argv); 23 | return 0; 24 | } 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ws10/minwithtemplateandoverloads/MyMaxTest.cpp: -------------------------------------------------------------------------------- 1 | #include "MyMax.h" 2 | #include 3 | #include 4 | void MyMaxTest(std::ostream &out){ 5 | using MyMax::max; 6 | int i = 88; 7 | out << "max(i,42) = " << max(i,42) << '\n'; 8 | double pi = 3.1415; 9 | double e = 2.7182; 10 | out << "max(e,pi) = " << max(e,pi) << '\n'; 11 | std::string s1 = "Hallo"; 12 | std::string s2 = "Hallihallo"; 13 | out << "max(Hallo,Hallihallo) = " << MyMax::max(s1,s2)<<'\n'; 14 | //max(2,pi); // compile error 15 | max(static_cast(2),pi); 16 | out << "max(Peter,Toni) = " 17 | << max("Peter","Toni") << '\n'; 18 | out << "max(Peter,Toni) = " 19 | << max("Peter","Toni") << '\n'; 20 | } 21 | -------------------------------------------------------------------------------- /CppAdvanced/other/old_w6/intiteratorboost/intiteratorboost.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | struct intiteratorboost 6 | : boost::input_iterator_helper 7 | { 8 | explicit intiteratorboost(int start=0):value{start}{} 9 | bool operator==(intiteratorboost const &r) const { 10 | return value == r.value; 11 | } 12 | value_type operator*() const { return value; } 13 | intiteratorboost &operator ++() { 14 | ++value; 15 | return *this; 16 | } 17 | private: 18 | int value; 19 | }; 20 | 21 | int main(){ 22 | copy(intiteratorboost{1},intiteratorboost{11}, 23 | std::ostream_iterator{std::cout,", "}); 24 | } 25 | -------------------------------------------------------------------------------- /solws04/FunctionValueTable/README.md: -------------------------------------------------------------------------------- 1 | This is a solution to exercise "Function-Value Table" 2 | 3 | Create a library with a function printFunctionTable that takes an ostream, a beginning and end value of type double, a number of steps, and a function as arguments. The function will produce a table of function values as follows by dividing the range given into n steps and prints the function results as follows: (start=1.0, end=3.0, steps=3, f(x) = [](double x){return x*x;}) 4 | 5 | `x 1.0 2.0 3.0 ` 6 | 7 | `f(x) 1.0 4.0 9.0 ` 8 | 9 | You might use a loop for the solution, or store the n used x values in a std::vector first, by using algorithm generate(_n). 10 | 11 | See the corresponding test cases for usage. -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/BoundedBufferTestat/src/n_times.h: -------------------------------------------------------------------------------- 1 | #ifndef N_TIMES_H_ 2 | #define N_TIMES_H_ 3 | 4 | 5 | namespace cpp_advanced { 6 | 7 | namespace times_literal { 8 | 9 | struct Executer { 10 | template 11 | void operator()(T const & action) const { 12 | for (auto i = 0u; i < times; i++) { 13 | action(); 14 | } 15 | } 16 | unsigned long long const times; 17 | }; 18 | 19 | constexpr auto operator"" _times(unsigned long long n) { 20 | return Executer{n}; 21 | // GCC Bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70979 22 | // return [n](auto f) { 23 | // for (auto i = 0u; i < n; i++) { 24 | // f(); 25 | // } 26 | // }; 27 | } 28 | 29 | } 30 | 31 | } 32 | 33 | #endif /* N_TIMES_H_ */ 34 | -------------------------------------------------------------------------------- /ws03/vectordemo/vectordemo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | std::vector v{1,2,3,4,5}; 7 | 8 | for (size_t i=0; i < v.size(); ++i){ 9 | std::cout << "v["<::size_type i=0; 12 | i < v.size(); ++i){ 13 | std::cout << v.at(i) <<'\n'; 14 | } 15 | 16 | for (auto &j:v){ 17 | j *= 2; 18 | } 19 | for (auto const i:v){ 20 | std::cout << "element: "<< i << '\n'; 21 | } 22 | 23 | for (auto it=begin(v); it!=end(v);++it){ 24 | std::cout << (*it)++ << ", "; 25 | } 26 | std::cout << '\n'; 27 | for (auto it=cbegin(v); it!=cend(v);++it){ 28 | std::cout << *it << ", "; 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws07/07_00_shape_and_square/shape_and_square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct Shape { 4 | virtual unsigned area() const = 0; 5 | virtual ~Shape() {} 6 | }; 7 | 8 | struct Square : Shape { 9 | Square(unsigned side_length) 10 | : side_length{side_length} {} 11 | unsigned area() const { 12 | return side_length * side_length; 13 | } 14 | unsigned const side_length; 15 | }; 16 | 17 | int main(int argc, char **argv) { 18 | //1 for non-virtual (empty) Shape 19 | //4 or 8 for virtual (empty) Shape 20 | std::cout << sizeof(Shape) << '\n'; 21 | 22 | //4 or 8 for non-virtual Square 23 | //8 to 16 for virtual Square 24 | std::cout << sizeof(Square) << '\n'; 25 | } 26 | -------------------------------------------------------------------------------- /ws10/shiftoperator/src/Test.cpp: -------------------------------------------------------------------------------- 1 | #include "cute.h" 2 | #include "ide_listener.h" 3 | #include "xml_listener.h" 4 | #include "cute_runner.h" 5 | 6 | void thisIsATest() { 7 | std::istringstream is{""}; 8 | int i{1}; 9 | is >> i; 10 | ASSERT(is.fail()); 11 | ASSERT_EQUAL(0,i); 12 | } 13 | 14 | void runAllTests(int argc, char const *argv[]){ 15 | cute::suite s; 16 | //TODO add your test here 17 | s.push_back(CUTE(thisIsATest)); 18 | cute::xml_file_opener xmlfile(argc,argv); 19 | cute::xml_listener > lis(xmlfile.out); 20 | cute::makeRunner(lis,argc,argv)(s, "AllTests"); 21 | } 22 | 23 | int main(int argc, char const *argv[]){ 24 | runAllTests(argc,argv); 25 | return 0; 26 | } 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /ws12/PIMPLexample/WizardPrePimpl.h: -------------------------------------------------------------------------------- 1 | #ifndef WIZARDPREPIMPL_H_ 2 | #define WIZARDPREPIMPL_H_ 3 | #include "WizardIngredients.h" 4 | #include 5 | #include 6 | namespace PrePimpl { 7 | 8 | class Wizard { // all magic details public 9 | std::string name; 10 | MagicWand wand; 11 | std::vector books; 12 | std::vector potions; 13 | std::string searchForSpell(std::string wish); 14 | Potion mixPotion(std::string recipe); 15 | void castSpell(std::string spell); 16 | void applyPotion(Potion phial); 17 | public: 18 | Wizard(std::string name="Rincewind"):name{name}, wand{}{} 19 | std::string doMagic(std::string wish); 20 | }; 21 | 22 | } /* namespace PrePimpl */ 23 | #endif /* WIZARDPREPIMPL_H_ */ 24 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/AtomicFlagExample/AtomicFlagExample.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std::this_thread; 5 | using namespace std::chrono_literals; 6 | void outputWhenReady(std::atomic_flag &flag 7 | , std::ostream &out){ 8 | while (flag.test_and_set(std::memory_order_acquire)) 9 | yield(); 10 | out<< "Here is thread: "<< get_id()<< std::endl; 11 | flag.clear(std::memory_order_release); 12 | } 13 | int main() { 14 | using std::cout; 15 | using std::endl; 16 | std::atomic_flag flag{}; 17 | 18 | std::thread t{[&flag]{ 19 | sleep_for(1ms); 20 | outputWhenReady(flag,cout); 21 | }}; 22 | sleep_for(1ms); 23 | outputWhenReady(flag,std::cout); 24 | t.join(); 25 | } 26 | -------------------------------------------------------------------------------- /CppAdvanced/other/user_defined_literals_ternary/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | namespace ternary { 7 | unsigned long long operator"" _3(char const *s) { 8 | size_t convertedupto { }; 9 | auto res = std::stoull(s, &convertedupto, 3u); 10 | if (convertedupto != strlen(s)) 11 | throw std::logic_error { "invalid ternary" }; 12 | return res; 13 | } 14 | } 15 | 16 | int main(int argc, char **argv) { 17 | using namespace ternary; 18 | int four = 11_3; 19 | std::cout << "four is " << four << '\n'; 20 | try { 21 | four = 14_3; // throws 22 | } catch (std::exception const &e) { 23 | std::cout << e.what() << '\n'; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /ws10/MinWithDefaultTemplateArgument/src/MyMin.h: -------------------------------------------------------------------------------- 1 | #ifndef MYMIN_H_ 2 | #define MYMIN_H_ 3 | 4 | namespace MyMin{ 5 | 6 | template 7 | auto min(T const& a, U const& b)->decltype(a 11 | void min(T * a, U * b)=delete; 12 | 13 | char const * min(char const* a, char const* b); 14 | 15 | } 16 | namespace MyMinBad{ 17 | 18 | template 19 | T min(T const& a, U const& b){ 20 | return (a < b)? a : b ; 21 | } 22 | template 23 | void min(T * a, U * b)=delete; 24 | 25 | char const * min(char const* a, char const* b); 26 | 27 | } 28 | 29 | #endif /*MYMIN_H_*/ 30 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws09/BoundedBufferArray/src/n_times.h: -------------------------------------------------------------------------------- 1 | #ifndef N_TIMES_H_ 2 | #define N_TIMES_H_ 3 | 4 | 5 | namespace cpp_advanced { 6 | 7 | namespace times_literal { 8 | 9 | struct Executer { 10 | template 11 | void operator()(T const & action) const { 12 | for (auto i = 0u; i < times; i++) { 13 | action(); 14 | } 15 | } 16 | unsigned long long const times; 17 | }; 18 | 19 | constexpr auto operator"" _times(unsigned long long n) { 20 | // return Executer{n}; 21 | // GCC Bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70979 22 | return [n](auto f) { 23 | for (auto i = 0u; i < n; i++) { 24 | f(); 25 | } 26 | }; 27 | } 28 | 29 | } 30 | 31 | } 32 | 33 | #endif /* N_TIMES_H_ */ 34 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/AtomicsAreLockFree/AtomicsAreLockFree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | template 4 | void printIsLockFree(std::ostream &out, std::string const &which 5 | , ATOM &atomic){ 6 | out << std::boolalpha <<"atomic<" 7 | << which << "> is_lock_free = " 8 | << atomic.is_lock_free()<<'\n'; 9 | } 10 | struct X{ 11 | char a[sizeof(void*)]; 12 | }; // must be trivially copyable and on my g++ not too big 13 | #define PRINT(type) { std::atomic const x{}; \ 14 | printIsLockFree(std::cout,#type,x);} 15 | int main() { 16 | using std::cout; 17 | using std::endl; 18 | PRINT(bool); 19 | PRINT(int); 20 | PRINT(double); 21 | PRINT(int64_t); 22 | PRINT(X); 23 | } 24 | -------------------------------------------------------------------------------- /CppAdvanced/cpla_ws10/SimpleThreadWrapper/src/ScopedThreadExample.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // adapted from Athony Williams: C++ Concurrency in Action 5 | struct scoped_thread{ 6 | scoped_thread(std::thread t) 7 | :the_thread{std::move(t)}{ 8 | if (! the_thread.joinable()) 9 | throw std::logic_error{"no thread"}; 10 | } 11 | ~scoped_thread(){ the_thread.join(); } 12 | private: 13 | // copying (and moving) is implicitly deleted 14 | // because std::thread is only movable 15 | std::thread the_thread; 16 | }; 17 | 18 | 19 | int main() { 20 | using std::cout; 21 | using std::endl; 22 | 23 | scoped_thread t{std::thread{ 24 | []{cout << "Hello Thread"<< endl;}}}; 25 | cout << "Hello Main" << endl; 26 | } 27 | -------------------------------------------------------------------------------- /ws10/minwithtemplatesandoverlaodsanddeletedoverloads/MyMaxTest.cpp: -------------------------------------------------------------------------------- 1 | #include "MyMax.h" 2 | #include 3 | #include 4 | void MyMaxTest(){ 5 | using MyMax::max; 6 | using std::cout; 7 | int i = 88; 8 | cout << "max(i,42) = " << max(i,42) << '\n'; 9 | double pi = 3.1415; 10 | double e = 2.7182; 11 | cout << "max(e,pi) = " << max(e,pi) << '\n'; 12 | std::string s1 = "Hallo"; 13 | std::string s2 = "Hallihallo"; 14 | cout << "max(Hallo,Hallihallo) = " << MyMax::max(s1,s2)<<'\n'; 15 | //max(2,pi); // compile error 16 | max(static_cast(2),pi); 17 | cout << "max(Peter,Tobi) = " 18 | << max("Peter","Tobi") << '\n'; 19 | cout << "max(Peter,Tobi) = " 20 | << max("Peter","Tobi") << '\n'; 21 | } 22 | --------------------------------------------------------------------------------