Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 15094

a design structure for creating several things that are almost identical but need different values. Not template-meta-programming.

6 votes
Accepted

Extended Euclidean Algorithm in modern and readable C++

The code is rather tiny so there isn't much to say, but I still have a couple of remarks: Since you're using C++17, you can take advantage of variable templates to simplify your static assertions a …
Morwenn's user avatar
  • 20k
2 votes
Accepted

Minimalist Tree

Most of the time we use it mostly because it is terser and convenient as well as reducing the refactoring cost when we need to modify the template parameters of the class. …
Morwenn's user avatar
  • 20k
4 votes
Accepted

Set openCV basic structures to zero in a unique way

Using it should allow you to always be safe but also to be safe when possible: template < typename Tp, int M, int N> void zero( cv::Matx<Tp, M, N>& m ) { std::fill(std::begin(m.val), std::end(m.val) … If you don't use a C++11 standard library, you can implement it as follows instead: template < typename Tp, int M, int N> void zero( cv::Matx<Tp, M, N>& m ) { std::fill(m.val, m.val + M*N, 0); } For …
Morwenn's user avatar
  • 20k
9 votes
2 answers
967 views

Template integer range, version 2

Step, bool IsIncreasing > struct integer_range_impl; template< typename Integer, Integer... … <std::size_t, Begin, End, Step>; Here is an example of how this template integer range can be used: #include <array> #include <iostream> #include <iterator> #include <numeric> template<typename T, …
Morwenn's user avatar
  • 20k
7 votes
1 answer
7k views

A trait class to detect whether a template is specialized for a given type

>::type; Here is the template utility I wrote to detect whether a template has a specialization for a given type, for SFINAE purpose: template< template<typename...> class, typename, typename … =void > struct is_specialized: std::false_type {}; template< template<typename...> class Template, typename T > struct is_specialized<Template, T, std::void_t<decltype(Template<T>{})>>: …
Morwenn's user avatar
  • 20k
4 votes
Accepted

C++ 2D shape intersections - template reduction

The intersect function First of all, I do believe that intersect should only be a free function that takes any number of mathematical objects and returns whether these objects intersect at some point …
Morwenn's user avatar
  • 20k
2 votes
Accepted

Template Method Checker

instead if not providing the body triggers some warnings so that you don't have to repeat the return type: static constexpr auto check(T *) -> typename std::is_same<decltype(std::declval<caller>().template
Morwenn's user avatar
  • 20k
2 votes

for_each_cons and for_each_slice, variants of std::for_each working on sliding windows

You don't have to always pollute the template parameters list when using the indices trick. … It will make it easier for users to understand the signature: template<typename It, typename Fun, std::size_t... …
Morwenn's user avatar
  • 20k
3 votes

Linear algebra module

In other words, make DenseBase take a Derived template parameter which corresponds to the type of the derived class: template <typename T, std::size_t M, std::size_t N, typename Derived> class DenseBase … { // ... } Then make the derived classes feed their own type to this template parameter: template <typename Parent, typename T, std::size_t N> class Rowview : public DenseBase<T, 1, N, Rowview< …
Morwenn's user avatar
  • 20k
8 votes
Accepted

A header-only linear-time C++11 PEG parser generator supporting left-recursion and grammar a...

You have "data" embedded in code in the function visit_left_binary_operator_list. You could use an std::unordered_map<char, double(*)(double, double)> to help separate the data and the actual algorith …
Morwenn's user avatar
  • 20k
4 votes

Using a CRTP approach for loading OpenGL programs

Nothing major, but here are a few things you could change: Since you don't define any special constructor/operator= in ProgramBase, you don't need to explicitly define its destructor. You can let th …
Morwenn's user avatar
  • 20k
16 votes
Accepted

Templated doubly-linked-list

The most frequent file extensions used for implementation files that cannot go into .cpp files are .inl (for inline) and .tpp (for template cpp). … When possible, try to use the injected class name in a cass template. …
Morwenn's user avatar
  • 20k
12 votes
1 answer
3k views

Compile-time-fixed templated integer range

struct decreasing_integer_range; template<typename Int, Int... … static_assert(N == 2, ""); } template<std::size_t N> void test(std::integer_sequence<int, -3, -2, -1, 0, 1>) { static_assert(N == 3, ""); } template<std::size_t N> void test(std::integer_sequence …
Morwenn's user avatar
  • 20k
7 votes

Smart enum templates

Since you have access to a C++11 compiler, you should use the standard type trait std::is_enum in the default version of your template instead of just writing is_enum = false. … Also, it should be constexpr: template<typename T> struct enum_properties { static constexpr bool is_enum = std::is_enum<T>::value; // ... }; Now, you don't have any mean to know whether T is …
Morwenn's user avatar
  • 20k
4 votes

Std lib-like C++ function to find nearest elements in a container

Therefore, you function declaration should be along these lines: template< typename T, typename InputIt, typename OutputIt, typename Distance, typename Compare = typename Comp<T, Distance … :size_t n, Distance dist, Compare comp = Compare()); That said, the standard library algorithms also tend to return the first iterator of the output range, so the declaration would become: template
Morwenn's user avatar
  • 20k

15 30 50 per page