Data dodania Pytanie
2018-02-18 10:02 Why does this std::vector::emplace_back fail? »
I'm coming across a compiler error that says: attempting to reference a deleted function #include <iostream> #include <vector> temp...
(1) odpowiedzi
2018-02-18 09:02 Default argument vs overloads in C++ »
For example, instead of void shared_ptr::reset() noexcept; template <typename Y> void shared_ptr::reset(Y* ptr); one may think of template &...
(4) odpowiedzi
2018-02-18 08:02 How does the compiler know the string literal (const char*) already exists in data memory? »
I have learned that char szA[] = "abc"; uses "abc" to initialize array szA, so it is stored in the stack memory and will be destroyed when function...
(3) odpowiedzi
2018-02-17 18:02 What is a module »
I have trouble understanding the concept of modules. Are they translation units? Are they like .ccp files and .h files?. In my textbook it is descri...
(1) odpowiedzi
2018-02-17 15:02 std::make_shared() change in C++17 »
In cppref, the following holds until C++17: code such as f(std::shared_ptr<int>(new int(42)), g()) can cause a memory leak if g gets calle...
(2) odpowiedzi
2018-02-17 09:02 C++ constant folding a loop for prime numbers »
Having had a look at previous questions 1, 2 , I was wondering if I can force the compiler to perform a constant folding for the following code which ...
(1) odpowiedzi
2018-02-16 15:02 How to rotate a matrix VIA edges »
I'm trying to solve this problem from HackerRank, I've made an solutions which works fine for any small example that you want to use, but I fail some ...
(0) odpowiedzi
2018-02-16 14:02 Is there any way to trace any compiler's template argument deduction? »
I am looking for way to get some trace log from compiler's logic when it is trying to deduce template argument types, whenever it successes or not. S...
(1) odpowiedzi
2018-02-16 11:02 Why can I modify the class with a const function in C++11? »
I'm a bit newbie to CPP and I don't know why the setValue() const works meanwhile it's a const. Why the class allows modification from a const public...
(3) odpowiedzi
2018-02-16 01:02 Is there any way for a C++ template function to take exactly N arguments? »
What I mean is, for example, a constructor for a class like the following: class vector<size_t N, typename FLOAT=double> { vector(FLOAT ......
(2) odpowiedzi
2018-02-15 23:02 Why std::get for variant throws on failure instead of being undefined behaviour? »
According to cppreference std::get for variant throws std::bad_variant_access if the type contained in the variant is not the expected one. This means...
(4) odpowiedzi
2018-02-15 15:02 C++ Zero-Initialization »
I'm having trouble understanding when and why exactly a member in my class is zero-initialized according to http://en.cppreference.com/w/cpp/language/...
(1) odpowiedzi
2018-02-15 05:02 Object passed to std::move but not moved from? »
I am reviewing some code like this, where A is a moveable type: // Returns true exactly when ownership of a is taken bool MaybeConsume(A&& a)...
(2) odpowiedzi
2018-02-14 23:02 Leaking C++ shared_ptr in Objective-C Block »
Summary: In the example application below, a shared_ptr is being captured in an Objective-C block. The Objective-C block is being assigned to an ivar...
(1) odpowiedzi
2018-02-14 15:02 Reinterpreting a union to a different union »
I have a standard-layout union that has a whole bunch of types in it: union Big { Hdr h; A a; B b; C c; D d; E e; F f; }...
(5) odpowiedzi
2018-02-14 12:02 Scope of a variable initialized in the parameter list of a function »
I've built, compiled and run the following code (C++, mingw) without any problems, but I'm unsure if it may be a ticking bomb: struct S { S() : a(0...
(2) odpowiedzi
2018-02-14 09:02 Is the object returned from a function still created when it is not used? »
Consider the following code. What happens when doStuff() is called but the return value is not used? Is SomeClass still created? Of course the creatio...
(2) odpowiedzi
2018-02-13 17:02 Is gcc or clang correct about this behavior? »
I have a little toy program: static int value = 0; int function(int &value=value) { return value; } int main() { function(); } Compil...
(3) odpowiedzi
2018-02-13 15:02 Should I always use braces when constructing objects? »
I read a lot about aggregate initialization but I still cannot understand what is the recommended way to construct an object. Suppose I have a class T...
(0) odpowiedzi
2018-02-13 14:02 Simple getter/accessor prevents vectorization - gcc bug? »
Consider this minimal implementation of a fixed vector<int>: constexpr std::size_t capacity = 1000; struct vec { int values[capacity]; ...
(0) odpowiedzi
2018-02-13 14:02 What happens when a destructor calls an abstract function »
I'm having trouble understanding what's the reason for the crash in the following code : class A { public: virtual ~A() { goo(); } void goo(...
(3) odpowiedzi
2018-02-12 20:02 how to compile a gem without compiler hardening in Ubuntu? »
I am using a gem that won't compile on Ubuntu because of what appears are compiler hardening settings. If I clone the gem's repo and modify the Makef...
(1) odpowiedzi
2018-02-12 19:02 template pointer parameter pack »
Why a template function with a template parameter pack of pointers cannot be instantiated with offsets of the same pointer? I mean: given this short ...
(2) odpowiedzi
2018-02-12 17:02 Most efficient way to get an integer type id in a family of common base types »
The problem: I have a family of objects with a common base, and I need to be able to identify the specific concrete type via an integer value. There...
(1) odpowiedzi
2018-02-12 16:02 Why is C++ much faster than python with boost? »
My goal is to write a small library for spectral finite elements in Python and to that purpose I tried extending python with a C++ library using Boost...
(2) odpowiedzi
2018-02-12 11:02 Is it guaranteed that std::vector default construction does not call new? »
According to the reference a simple std::vector<T> vec; creates an emtpy container (default constructor). Does this guarantee that there is no d...
(2) odpowiedzi
2018-02-11 13:02 Program behaving strangely on online IDEs »
I have come across the below C++ program (source): #include <iostream> int main() { for (int i = 0; i < 300; i++) std::cout <...
(4) odpowiedzi
2018-02-11 08:02 Is there still a reason to use `int` in C++ code? »
Many style guides such as the Google one recommend to use int as a default integer, when indexing arrays for instance. With the rise of 64-bit platfor...
(10) odpowiedzi
2018-02-11 04:02 Why elements can be inserted in a vector when using const_iterators »
Considering the code below, #include <iostream> #include <algorithm> #include <vector> using namespace std; int main(){ vector...
(2) odpowiedzi
2018-02-10 19:02 How to order types at compile-time? »
Consider the following program: #include <tuple> #include <vector> #include <iostream> #include <type_traits> template <c...
(1) odpowiedzi
2018-02-10 14:02 Does it make sense to combine optional with reference_wrapper? »
It occurred to me that in C++ it is possible to use the type std::optional<std::reference_wrapper<T>>. An object of this type is essential...
(1) odpowiedzi
2018-02-10 10:02 What is safe? returning a structure or the pointer from a function »
#include <iostream> struct person_t{ int age; }; person_t get_person1(){ person_t person; person.age = 10; ret...
(4) odpowiedzi
2018-02-09 18:02 Get string length function (strlen) of a constant char array is not a constant expression »
Let's see the simplified code directly (compiled by: GCC 6.3.0) #include<iostream> #include<cstring> using namespace std; int main(int ...
(1) odpowiedzi
2018-02-09 11:02 C++ ISO noexcept of noexcept »
In the C++ standard (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf) There is the following definition: template <class T, siz...
(1) odpowiedzi
2018-02-09 11:02 How to write operator== to work with implicitly casted/constructed types »
Why this does not work, since there is option to 'construct' implicitly? class A {}; template<typename T> class Type { public: Type() = d...
(4) odpowiedzi