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.

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 …
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 …
Edward's user avatar
  • 66.6k
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, …
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. …
Community's user avatar
  • 1
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
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>{})>>: …
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
7 votes

Template vector struct in C11

I did manage to improve some things since the question was posted. So here is what I discovered, that could somehow improve the implementation and the usability of the Vector(T): First of all, there …
Morwenn's user avatar
  • 20k
17 votes
2 answers
5k views

Template vector struct in C11

This one review will be a little bit tricky: I was trying to implement a template Vector struct in C11. …
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
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
18 votes

Dynamically call lambda based on stream input

arguments whose types have been deduced, I would have passed args by universal reference (now officially called forwarding reference) and used std::forward to forward the results to the following functions: template … and quite long to explain how it works exactly - you can find a great explanation in the answer linked above -, but the main point is that using this particular recipe implements perfect forwarding: template
Community's user avatar
  • 1

15 30 50 per page