c++14 Questions
2
Solved
I lately tried to do something like this:
auto x = std::make_unique<int>(1);
auto l = [y = std::move(x)]() { return *y; };
std::function<void()> f(std::move(l)); //error, requires copy...
3
Solved
In the question Idiom for initializing an std::array using a generator function taking the index?,which basically asks how one can initialize an array of an arbitrary type which is not necessarily ...
Gribble asked 26/6 at 14:23
9
Given the following code:
struct Window{
void show();
//stuff
}w1, w2, w3;
struct Widget{
void show();
//stuff
}w4, w5, w6;
struct Toolbar{
void show();
//stuff
}t1, t2, t3;
I want to sh...
5
Solved
I try next code with three compilers (msvc2017, gcc8.2, clang7.0) and msvc2017 works all the way, but gcc and clang not. I want to understand what is wrong with my code, and why compiler can't comp...
8
Solved
Is there a standard way to get the types of a function's arguments and pass around these types as a template parameter pack? I know that this is possible in C++ because it has been done before.
I ...
Catamaran asked 13/2, 2015 at 21:45
5
Solved
I would like to declare a lambda function with exactly N parameters, where N is a template argument. Something like...
template <int N>
class A {
std::function<void (double, ..., double)...
6
Solved
I'd like a constexpr function that will return me a unique id for every C++ type, something like this:
using typeid_t = uintptr_t;
template <typename T>
constexpr typeid_t type_id() noexcep...
3
Solved
I am storing the ownership of some objects inside an unordered_set, using unique_ptrs.
But I don't know a good way to erase one of them from the set, when the time comes.
Code looks something like...
Kodok asked 14/2, 2020 at 4:57
2
Solved
The following program attempts to construct a second string using the first string and a pointer into the middle of the first string:
#include <string>
int main() {
std::string src = "hell...
2
Solved
because I want to overload all cv and reference qualifications of a member function, I wrote myself the following macro:
#define DEFINE_FUNCTION(sig , functionality) \
sig & { functionality; ...
4
Solved
The description of std::is_void states that:
Provides the member constant value that is equal to true, if T is the type void, const void, volatile
void, or const volatile void.
Then what could be...
Metameric asked 17/6, 2016 at 12:9
3
Solved
I have been trying to write my own vector class to better understand C++ templates and iterators, but have been stuck with this error for a while and would really appreciate the help.
The code fail...
3
Solved
I'd like to have a function BindFirst that binds the first argument of a function without me having to explicitly know/state the arity of the function by using std::placeholders. I'd like the clien...
Duong asked 15/11, 2015 at 19:32
3
Solved
I was reading Effective Modern C++ Item 25, on page 172, it has an example to demonstrate that, if you want to move return an rvalue reference parameter, you need to wrap it with std::move(param). ...
2
Solved
Suppose I have a constexpr array (of known bound) of static storage duration:
constexpr T input[] = /* ... */;
And I have an output class template that needs a pack:
template<T...> struct...
Stereography asked 3/7, 2014 at 18:5
3
Solved
I rarely see decltype(auto) but when I do it confuses me because it seems to do the same thing as auto when returning from a function.
auto g() { return expr; }
decltype(auto) g() { return expr; }...
2
Solved
I want to compute a lookup table at compile time for a mathematical function in a given range and then retrieve values from the table at run time. My code is as follows:
#include <iostream>
...
5
Solved
I have the following case that works using std::enable_if :
template<typename T,
typename std::enable_if<std::is_same<int, T>::value>::type* = nullptr>
void f() { }
template&l...
4
Solved
I am trying to really move from c++98 to c++11 and newer. I have wrapped my head over most of the new stuff but I am still not sure about the correct usage of unique_ptr.
Consider the example belo...
Pedicle asked 4/3, 2017 at 11:31
2
Solved
I've been reading a book about C++14/11. I just finished reading a chapter about the constexpr keyword. I know what it's used for, but how often should I use constexpr? Should I use it even in code...
2
Solved
This code compiles and executes fine using GCC 13 and Clang 17, but fails to compile on MSVC. I am wondering if the code is required to work according to the standard or if this is a problem with M...
Bunghole asked 9/11, 2023 at 8:20
11
Solved
Is there a nice way to iterate over at most N elements in a container using a range-based for loop and/or algorithms from the standard library (that's the whole point, I know I can just use the &qu...
2
Solved
In C++14, how do I initialize a global constexpr std::array of std::pair containing text strings? The following doesn't work:
#include <array>
constexpr std::array<std::pair<int, cons...
7
Using both gcc with -std=c11 and g++ with -std=c++14.
E.g. for a file named src/dir/Hello.cxx it should expand to something like e.g.:
const char basename[] = "Hello";
or
const char basename[]...
8
Solved
Since the extended versions of constexpr (I think from C++14) you can declare constexpr functions that could be used as "real" constexpr. That is, the code is executed at compile time or ...
Tiber asked 24/10, 2017 at 20:37
1 Next >
© 2022 - 2024 — McMap. All rights reserved.