Search Results
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 |
a design structure for creating several things that are almost identical but need different values. Not template-meta-programming.
5
votes
Accepted
Template data types implementation
Here are some small things you could di in order to improve your design:
First of all, you have a typo: you wrote Map::Iiterator begin(); instead of Map::Iterator begin();.
You use KeyType and DataT …
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 …
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 …
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, …
13
votes
3
answers
2k
views
Expression template to compute the Euclidean distance
I was writing some geometry-related code again and had a closer look at my function supposed to compute the Euclidean distance between two points (N-dimensional points by the way, hence the N template … Here is a simplified version:
template<std::size_t N, typename T>
auto distance(const Point<N, T>& lhs, const Point<N, T>& rhs)
-> T
{
T res{};
for (std::size_t i = 0 ; i < N ; ++i)
{ …
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 …
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 …
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< …
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 …
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 …
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>{})>>: …
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 …
5
votes
Accepted
Dynamically call lambda based on stream input: Try 3
(Args);
typedef std::tuple<std::decay_t<Args>...> AllArgs;
};
template<typename StreamValueGetter, typename Action, typename Stream, std::size_t... … action(StreamValueGetter::template get<std::tuple_element_t<S, ArgumentTuple>>(stream)...);
}
template<typename StreamValueGetter, typename Action, typename Stream>
void callFunctor(Stream& stream, Action …
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 …
13
votes
Accepted
Variadic templates and pointers to member functions to achieve a named-parameters interface ...
For example, you could turn this piece of code:
template<typename T, typename S, typename ...Args>
void apply(T *t, const S & setter, const Args &... args) {
t->set(setter);
apply(t, args...);
} … into this one:
template<typename T, typename S, typename ...Args>
void apply(T *t, const S & setter, Args &&... args) {
t->set(setter);
apply(t, std::forward<Args>(args)...);
}
std::unique_ptr …