Data dodania Pytanie
2017-06-19 13:06 The use of double include guards in C++ »
So I recently had a discussion where I work, in which I was questioning the use of a double include guard over a single guard. What I mean by double g...
(5) odpowiedzi
2017-06-19 07:06 What is the C++ equivalent of Python's "in" operator? »
What is the C++ way of checking if an element is contained in an array/list, similar to what the in operator does in Python? if x in arr: print "...
(6) odpowiedzi
2017-06-19 03:06 g++ and clang++ different behaviour with alias template »
Trying to respond to another question, I've written the following code that behave different in g++ (6.3.0) and in clang++ (3.8.1) #include <iostr...
(0) odpowiedzi
2017-06-18 12:06 What is the syntax to be used for feed_dict in TensorFlow C++? »
I want to build and train a graph in TensorFlow C++ that consists of two layers, and to feed it with a given matrix as an input. I have two different...
(1) odpowiedzi
2017-06-18 12:06 Using the class name 'Object' in C++ is desirable? »
I think this is not the kind of question that has a definite answer, but has various opinions depending on one's preference. When naming a class, so...
(0) odpowiedzi
2017-06-18 10:06 C++ template partial specialization - Most specialized with unique_ptr<t> »
I am trying to create partially specialized template, and have specialize even further if passed a std::unique_ptr template <typename T, typename ...
(3) odpowiedzi
2017-06-18 08:06 Why can't the compiler deduce the template parameter when used with a conversion operator? »
Consider the following code: #include <utility> template<typename T> struct wrapper { T value; }; struct foo { operator wrapper...
(1) odpowiedzi
2017-06-17 10:06 Pointers: initialisation vs. declaration »
I am a C++ noob and I am quite sure this is a stupid question, but I just do not quite understand why an error arises (does not arise) from the follow...
(6) odpowiedzi
2017-06-17 08:06 Why doesn't a reference to an array work until we use a pointer? »
This works very well... int a[5] = {1,2,3,4,5}, int *p = a; int *& ref = p; But why doesn't this work? int a[5] = {1,2,3,4,5}; int*& ref =...
(3) odpowiedzi
2017-06-17 04:06 Shocked by the strange behavior of unordered_map »
It is a very simple piece of code: #include <cstdio> #include <unordered_map> int main() { std::unordered_map<int, int> m; ...
(2) odpowiedzi
2017-06-16 13:06 Malloc vs New for Primitives »
I understand the benefits of using new against malloc in C++. But for specific cases such as primitive data types (non array) - int, float etc, is it ...
(4) odpowiedzi
2017-06-16 13:06 Default value of function parameter initialized by list initialization »
Could anyone help me with the following problem? There is a simple code: #include <vector> struct A { std::vector<int> vec; }; voi...
(2) odpowiedzi
2017-06-16 11:06 Partial template function specialization with enable_if: make default implementation »
Using C++11's enable_if I want to define several specialized implementations for a function (based on the type of the parameter, say) as well as a def...
(3) odpowiedzi
2017-06-15 19:06 Overload resolution with an empty brace initializer: pointer or reference? »
I ran into a real-life WTF moment when I discovered that the code below outputs "pointer". #include <iostream> #include <utility> templa...
(1) odpowiedzi
2017-06-15 12:06 How to enable C++ warnings for bitwise operators with boolean arguments »
While working with a rather large C++ code base and the GCC toolchain on Linux, I have encountered code which performs a boolean check as follows: #i...
(1) odpowiedzi
2017-06-15 10:06 How can I force template parameter type to be signed? »
I'll use the following example to illustrate my question: template<typename T> T diff(T a, T b) { return a-b; } I expect this template func...
(7) odpowiedzi
2017-06-14 21:06 Overloading operators: operand order when using C++ literals »
I am writing a class and I got to the point where I can do operations that mix my class type objects and C++ literals, but in one direction only. her...
(2) odpowiedzi
2017-06-14 16:06 Covariant return type is not recognized »
For some reason, up-to-date versions of both GCC and clang do not recognize return type covariance in this particular scenario. The error message is m...
(1) odpowiedzi
2017-06-14 12:06 Dispatching r-values and l-values differently and using sfinae to disable one option »
I would like to implement a function drop_if. Given a unary predicate and a sequential container, it returns a container of the same type holding only...
(4) odpowiedzi
2017-06-14 08:06 How to define a tuple of value types from a parameter pack »
I need to build a tuple of n types. These n types are value types of n other types. Consider this snippet: #include <boost/hana.hpp> namespace...
(2) odpowiedzi
2017-06-13 21:06 Safety of std::unordered_map::merge() »
While writing some code targeting C++17, I kind of hit a stumbling block determining the exception-safety of an operation merging two compatible std::...
(0) odpowiedzi
2017-06-13 15:06 Accessing child variables through higher level structures »
If I have these structures: typedef struct { int x; } foo; typedef struct { foo f; } bar; Normally you would access x through b.f.x, but is there a...
(8) odpowiedzi
2017-06-13 13:06 Fastest `finally` for C++ »
C++ so far (unfortunately) doesn't support finally clause for a try statement. This leads to speculations on how to release resources. After studying ...
(2) odpowiedzi
2017-06-13 13:06 How to define a custom cross-platform size_t type? »
std::size_t is commonly used for array indexing and loop counting. By definition, std::size_t is the unsigned integer type of the result of the sizeof...
(3) odpowiedzi
2017-06-13 06:06 How do I Avoid Common Pitfalls and See the Overall Picture While Learning C++? »
I have a research job this summer where I need to use C++ everyday full time. I'm coming into the job with only passing familiarity with the language ...
(0) odpowiedzi
2017-06-12 22:06 Why is `std::byte` an enum class instead of a class? »
std::byte is an abstraction that is supposed to provide a type safe(r) access to regions of memory in C++, starting with the new standard 17. However,...
(1) odpowiedzi
2017-06-12 03:06 ADL fails (or not done?) for function with additional (non deduced) template parameter »
namespace N { class C {}; template<typename X> char const * found(X && x) { return "found"; } template<...
(1) odpowiedzi
2017-06-12 01:06 Why don't C++ compilers optimize this dynamic_cast from a final class? »
Consider this class hierarchy: struct Animal { virtual ~Animal(); }; struct Cat : virtual Animal {}; struct Dog final : virtual Animal {}; My under...
(1) odpowiedzi
2017-06-11 19:06 Does using std::get on std::array give better performance? »
The Standard Library class template std::array<T, N> has both a member accessor function constexpr const T& operator[]( size_type n ) const...
(2) odpowiedzi
2017-06-11 17:06 Using a relative path in executable with symbolic link »
I'm trying to figure out how to use my application with a link in ubuntu. I've compiled the code and it contains relative paths to certain files. When...
(0) odpowiedzi
2017-06-11 17:06 Will I be able to declare constexpr lambda inside a template parameter »
I know it's like opening the Pandora box but it doesn't stop bothering me. Consider a simple example: #include <type_traits> template <auto...
(1) odpowiedzi
2017-06-11 13:06 What is the data type of a single character in a string as an array? »
string s; cin>>s; suppose s = "stackoverflow" now if we access s[3], it should give out 'c' will s[3] be 'c' or "c"? as in will it be a ch...
(3) odpowiedzi
2017-06-10 23:06 Why can't we implement both methods `getAB() &&` and `getAB()`? »
Why can't we implement both methods getAB() && and getAB(), but can implement any one of these? Works: http://ideone.com/4EgObJ Code: str...
(1) odpowiedzi
2017-06-10 21:06 C++ Code GameState if else statements and GameState isn't going in the correct order »
I am having this problem with my code: #include <iostream> #include <vector> #include <map> using namespace std; enum { DEATH, ROO...
(1) odpowiedzi
2017-06-10 17:06 c++ static lambda performance »
I stumbled upon this code that is using c++ lambda: qreal defaultDpiScale() { static qreal scale = []() { if (const QScreen *screen = QGu...
(1) odpowiedzi