Questions tagged [c++14]
C++14 is the version of C++ after C++11. This tag should be used (along with the [C++] tag) for questions about C++ features specific to C++14.
8,511
questions
0
votes
0
answers
23
views
ctime is occasionally spitting out the wrong time string
I am on a custom board that is running qnx. I was using the ctime function to convert a std::time_point to a human readable time.
This is the function:
auto TimePointAsString(const std::chrono::...
0
votes
0
answers
11
views
Debugging issue - Calculator08buggy.cpp from Programming principles and practice of Bjarne Stroustrup
As part of the drill I need to find 3 errors in the code, but I was just able to solve one were I just needed to declare a construct for Token(name, s). I need clues in what other things could be ...
-3
votes
0
answers
32
views
Why is a reference to a static variable unresolved in the linker? [duplicate]
Win11
MSVC 2022 (64-bit) - Version 17.8.0
C++14
I have a simple program, below. I can not reference the static variables within a function in the source code (*.cpp file), but I can reference object ...
0
votes
3
answers
149
views
C++14 How to init vector<vector<unique_ptr<MyClass>>> with nullptr
I need to create a vector of vectors containing null unique_ptr at runtime.
int display_page_count;
vector<vector<unique_ptr<MyClass>>> pages_objects; // Declaration
my goal is to ...
-3
votes
0
answers
36
views
Is there any method to split flatbuffer output as '.h' and '.cpp' [closed]
The build time is long for flatbuffers is the generated code is all '*generated.h'.
This potentially results in recompilation of headers multiple times.
Is there any solution to split flatbuffer ...
0
votes
1
answer
78
views
How to determine boost::optional's (and other) API's?
I was trying to go through the boost optional documentation, and I find this with all of the boost docs in that I can't find a clear API definition. I want to determine:
Is there is an operator& ...
-3
votes
1
answer
58
views
constexpr member functions gives C2131 [duplicate]
I've understood the differences between const and constexpr and their applications, but I can't get it's the following error:
// .hpp file
class MyClass {
public:
constexpr double Square(double ...
0
votes
1
answer
120
views
How to iterate over ranges of a std::vector
I have a question on what's the best way to iterate over slices/ranges of a vector with C++11 or C++14. Let's say we have a std::vector that holds a bunch of values:
std::vector<int> v = {0,1,2,...
0
votes
2
answers
90
views
Initializing an array of string pairs without mentioning explicit type
I'm trying to initialize an std::array of std::pair<std::string, std::string> but am unable to do it at the site of calling without explicitly including the std::pair type.
Here's the complete ...
0
votes
3
answers
125
views
C++ equivalent of Java's method references?
I have a std::vector<std::vector<int>>, from which I want to check whether there is at least 1 sub-vector that's empty. So I have this:
std::any_of(vec.begin(), vec.end(), [](const auto&...
1
vote
0
answers
104
views
C++ 14 - union - Is it legal to access inactive member?
After read a lot about it, I'm confused about if it is legal or not accessing to inactive member of an union starting from C++14. I understood it is undefined behaviour up to C++11.
Some references:
...
0
votes
0
answers
43
views
creating an pod_tuple-class which is standard layout and trivially copyable with some type-modifications
I am trying to write a pod_tuple-class which is trivially copyable and standard layout (of course only if that also counts for the types itself). it should feel the same like std::tuple but does only ...
0
votes
0
answers
60
views
Is it valid to combine friending and templating in this code?
This code compiles in GCC, clang etc
template <int a, typename T>
class A{
private:
int B=1;
friend A<-a, T> func(A a_in){
A<-a, T> ...
21
votes
2
answers
1k
views
Are enum values allowed in a std::integer_sequence?
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 MSVC....
0
votes
1
answer
70
views
SFINAE for constructing classes with function-type template parameter, based on the type of parameter for the function
it's not easy to summarize the topic in a catchy title.
My problem is the following:
I want to call different implementations of a create-function which gives me back a pointer to a callee which is ...
-1
votes
4
answers
225
views
Shared Pointer query in an interview [closed]
which is better among the following codes
int *a=new int();
shared_ptr<int> sh(a);
or this
shared_ptr<int> sh(new int());
The interviewer was hinting that the first case has a problem ...
-3
votes
0
answers
68
views
Why are Static variables not allowed in constexpr function? [duplicate]
As we know constexpr function are functions that can be evaluated either at compiletime or at runtime, which depends on various factors(like whether the arguments passed are constexpr or whether the ...
-5
votes
1
answer
117
views
Template member function cannot be explicitly specialized
I have a declaration of a function in class
class A {
template<typename T, typename... ARGS>
void Func( ARGS&&... args) {
//DoSomeWork
}
};
and then try to specialize it for ...
-1
votes
0
answers
33
views
C++ program error: undefined reference to one of my functions [duplicate]
I have a async_test cpp file that is going to test my async.cpp implementation, but after compiling, I am unable to use my async_read function to test. I get the following error below:
async.cpp:88: ...
0
votes
1
answer
135
views
Assign a function return-value to std::vector element: Different behavior in C++14 than in C++17
Assertion failed and has undefined behavior
#include<bits/stdc++.h>
const int MaxN = 1e5 + 10;
struct Node{
long long sum;
int left,right;
Node() :sum(0),left(0),right(0){
}
...
2
votes
1
answer
73
views
How to Serialize/Deserialize an unordered_map member of a derived Class
So I'm building a simulated file-system in C++ to study the language better and maybe some system level programming. Im using Boost::Serialization to save the state of the file system when the user ...
0
votes
0
answers
16
views
google cloud sdk c++ client
When I try to compile this code which is given in README, Getting undefined reference to google::cloud::storage::v2_18::Client::Client(google::cloud::v2_18::Options)
I don;t see anywhere the ...
0
votes
1
answer
62
views
Replace template parameter list with variadic parameter
Can someone help with how I can replace a list of template types with a variadic template parameter and create unique pointers of each type within the class.
The problem is I have a class
template <...
2
votes
2
answers
135
views
How do I concatenate strings repeatedly at compile time?
I wrote the following code for using string in compile time:
template<char... Chars>
struct CnstString {
template<char... Aped>
using push_back = CnstString<Chars..., Aped...>...
0
votes
0
answers
26
views
not getting the desired result
I has written the following code for fast exponential in coding Ninza I do not got the correct answer. My calculation part is correct, till calculating the exponent but I am unable to calculate the ...
2
votes
3
answers
181
views
How to restrict function template arguments to be specializations of a specific class template
I have a structure like:
template <typename Arg1, typename Arg2>
class TemplateClass { ... };
template <typename TClass>
class UsesTemplateClass {
public:
UsesTemplateClass( TClass&...
1
vote
0
answers
68
views
How do I write enum classes within enum classes in C++?
I am writing part of a larger C++ program.
I want to write a header file, say, "Component.h", with code like this...
class Component{
private:
int value;
ComponentType ...
-1
votes
1
answer
93
views
Is there any potential problem if appending more enumeration in an the header of a library which is provided by others?
Is there any potential problem that I shoud be aware of if appending more enumeration in an the header of a shared library which is provided by others? The code of the said libray could not be ...
1
vote
1
answer
63
views
How the bool operator of std::shared_ptr is trrigered in the expression(i.e. `bool is_empty = shared_ptr1 && shared_ptr2;` )?
Gaven that cur_front_res and cur_back_res are both shared_ptr, how the bool operator of std::shared_ptr is trigered in the expression(i.e. bool is_empty = cur_front_res && cur_back_res; )?
...
2
votes
2
answers
79
views
Is it safe to use std::shared_ptr between productor and consumer when the shared managed object would never be acessed at the same time?
Here is the demo code snippet below.
Could the mutex be removed since std::shared_ptr itself is thread-safe and the managed object would never be accessed by productor and consumer at the same time?
#...
1
vote
1
answer
25
views
How do I enforce Qi spirit rule to try all rules in OR condition?
I'm trying to parse this command template that can take the following:
SendCmd SomeCommand Left_Side = "Some Value";
SendCmd AnotherCmd "Some Literal" = Some_Value;
SendCmd ...
2
votes
1
answer
58
views
c++ 14 Categorized List of 3 Strings
My brain is fried this morning, and I am struggling to understand why I am getting a compiler error.
error: no matching constructor for initialization of 'list<data::tweak_cat>'
My code is this:
...
0
votes
0
answers
92
views
Marshal struct and pointer in struct from c# to c++
I have the following structures in C# and C++.
C++:
typedef struct _st_a {
double dLon;
double dLat;
double dE;
double dN;
double dU;
} ST_A;
typedef struct _st_b {
unsigned ...
1
vote
1
answer
86
views
How to convert a string literal to a character sequence and assign it to a template class's parameter pack char... C in C++14?
For example, I have a template struct String that accepts a parameter pack of characters.
template<char ...pack>
struct String{}
How can I implement the code to make String<"abcd"&...
19
votes
2
answers
2k
views
Is it ok to use std::ignore in order to discard a return value of a function to avoid any related compiler warnings?
I know that you can use static_cast<void>, but it just seems too verbose for me, and not reflecting the original intent that I want to discard a return value, not to cast it to anything.
...
1
vote
1
answer
75
views
Get Unicode from json file
I am working on a C++ project (C++14) and I am facing the following issue. I have a JSON file with a field containing Unicode characters. I am using nlohmann/json to retrieve information from this ...
0
votes
0
answers
29
views
C++ SDL_ttf cannot find freetype262.dll
i am trying to make a project in SDL2 C++ and use SDL_ttf.h, to draw text, but when i run it (i am only using TTF_Init() here, nothing else) i get the error "could not find "freetype262.dll&...
1
vote
2
answers
92
views
delete constructor in C++: private/protected/public?
what is the best practice to delete constructor in C++: put it in private/protected/public ?:
approach 1:
class Foo{
public:
Foo() = delete;
}
approach 2:
class Foo{
protected:
Foo() = delete;
}
...
0
votes
0
answers
12
views
How to resize n-dimensional array using method in template class?
I want to create some class which let us do operations on n-dimensional vectors (finally my goal is having a tensor class). Firstly I used generation of data type of such tensors from here.
template&...
1
vote
1
answer
73
views
How to initialize a data member of an array type in a class template's member initializer list?
For example, I have a class called Vector that represents a vector and a class called Integer that represents an integer.
class Integer{
public:
Integer(int v):value_(v){};
private:
int value_;
}...
1
vote
1
answer
55
views
Copy elision of overlapping objects
Reference: Copy Elision
This can only apply when the object being initialized is known not to be a potentially-overlapping subobject:
struct C { /* ... */ };
C f();
struct D;
D g();
struct D : C
{
...
1
vote
2
answers
79
views
How to prevent a segment of Side Effect-Free code from being optimized away?
Consider a scenario where I have constructed a class T that represents large integers. This class T has an addition operator function.
class T {
public:
T operator+(const T &other) const
}
In ...
-3
votes
1
answer
51
views
error: use of deleted function ‘std::atomic<unsigned int>::atomic(const std::atomic<unsigned int>&)’ [duplicate]
While trying to compile the code base of a project from a Git repository, I came across the following error:
DGSF-AvA/worker/serverless_gpu/svgpu_manager.cpp:90:78: error: use of deleted function ‘std:...
16
votes
4
answers
2k
views
What is the purpose of _t aliases and _v variable templates for type traits?
There are a lot of *_v and *_t suffixes, like std::is_same_v, std::invoke_result_t, result_of_t and milions of other such functions.
Why do they exist at all? Is it beneficial in any context to expose ...
1
vote
1
answer
54
views
Creating a packed version of a template class in C++14
I would like to make an __attribute__((packed)) version of a template class, to use it in packed structs to send or receive as bytes. But I don't want the cost of packed to impact the arithmetic and ...
1
vote
2
answers
69
views
Adding optional argument to variadiac class template (C++14)
in our C++14 code base our modules have two types of extensions. Imagine group A as a run-at-start-up type, and type B as run-at-shut-down. The module is simply handed a list of all extension and ...
1
vote
0
answers
80
views
Are functions pointers a safe alternative to tightly coupled classes?
Let’s say MyClass needs info from the Util class. Is the following example of function pointer use safe? Note that this is running on an embedded system where CPU resources are tight.
Correct me if I’...
10
votes
1
answer
199
views
Why does a variable refer to the variable outside of a lambda, if it is not odr used?
Look at this example (godbolt):
void foo(int &par) {
auto l = [par]() {
decltype(par) x;
};
}
This program does not compile, because the par in decltype(par) refers to the ...
0
votes
0
answers
28
views
Error from openCV: cuda.hpp(115): error C2059: syntax error: 'constant' when building my C++ Application
I have a C++ 32-bit application, and i wanted to use opencv APIs for Image processing mainly. I have built the openCV 4.8.0 source code using cmake and Msbuild utility which has created openCV .lib ...
0
votes
1
answer
213
views
Is C++ machine-independent or machine-dependent? [closed]
https://www.geeksforgeeks.org/introduction-to-c-programming-language/
Under some keys & features
Machine Independent but Platform Dependent: A C++ executable is not platform-independent (compiled ...