Category : templates

I use the following code to compare arithmetic types. The class template equal compares the given arguments for equality and stores the result in the member variable result. The class template also provides a cast operator to bool in order to be evaluated in conditional statements. I also provide a template deduction guide in order ..

Read more

Consider this class: class Person { std::string name; std::string last; int age; public: template<typename T1, typename T2> Person(T1&& name, T2&& last, int age) noexcept : name(std::forward<T1>(name)) , last(std::forward<T2>(last)) , age(age) {} Person(const Person& other) noexcept = default; Person(Person&& old) noexcept = default; Person& operator=(const Person& other) noexcept = default; Person& operator=(Person&& old) noexcept = default; ..

Read more

I have a struct with several (virtual) bases. From one of these bases’ constructor I static_cast to the most derived type, and from there try access a member of another base (which has been initialised before). The adress doesn’t match with the result when accessing from the most derived struct’s constructor directly. Weirdly (at least ..

Read more

I’m a prof c# developper but I’m trying to write some code in C++ (for arduino purpose). When I compile my code I have this error message "undefined reference to `NEOPATTERNController<(unsigned char)3, (EOrder)66>::SetPattern(PatternEnum)’" this is my code: -cpp file #include <neopattern.h> template<uint8_t DATA_PIN, EOrder RGB_ORDER > void NEOPATTERNController<DATA_PIN, RGB_ORDER>::SetPattern(PatternEnum pattern) { } // No need ..

Read more

I have template class and some Policies to use it. It just execute lambdas with specific policy. template<template<class>class Policy, typename ReturnType> class execute :Policy<ReturnType> { public: ReturnType res; execute(ReturnType(*func)()) {res = Policy<ReturnType>().launch(func);} }; template<typename ReturnType> struct Policy1 { ReturnType launch(ReturnType(*func)()) {/*some code*/ return func();} }; template<typename ReturnType> struct Policy2 { ReturnType launch(ReturnType(*func)()) {/*some code*/ return ..

Read more