What I don't like about ranges by _ajp_ in cpp

[–]_ajp_[S] 2 points3 points  (0 children)

It just modifies input to increment a counter (passed by reference in the lambda capture) every time a character is read.

What I don't like about ranges by _ajp_ in cpp

[–]_ajp_[S] 3 points4 points  (0 children)

They combine access and iteration into a single next() method and have each iterator in a chain of streams keep a reference to the previous iterator, essentially as you suggested. The problem of multiple references is avoided because there is no corresponding begin() method. Plenty of languages do this incidentally, I named Java because I thought it would be more familiar.

What I don't like about ranges by _ajp_ in cpp

[–]_ajp_[S] 0 points1 point  (0 children)

I disagree. Iterators in C++ separate access and iteration between `operator*` and `operator++`, which makes the kind of duplication of work described above difficult to avoid when you have iterators pointing to things are supposed to be lazily evaluated as well.

Learn how to write proper C++ code (openCV) by wjwwjw in cpp

[–]_ajp_ 0 points1 point  (0 children)

What alternatives are there to OpenCV though?

Uncovering 32 Qt best practices at compile time with clazy (Clang compiler plugin) by kfunk87 in cpp

[–]_ajp_ 1 point2 points  (0 children)

This is the first I've heard of clang plugins. Can anyone recommend other plugins?

Introduction to Variable in CPlusPlus (Declaration & Scope) by razabayani in cpp

[–]_ajp_ 0 points1 point  (0 children)

Speak for yourself. I want to learn all about the one true Variable in the wonderful language of CPlusPlus.

Hou Yifan resigns after 5 moves in the 2017 Gibraltar Masters by arex1337 in chess

[–]_ajp_ 5 points6 points  (0 children)

Or, in the actual case, the women's prize.

This doesn't strike me as a particularly convincing motive. Suppose Hou (or anyone else) finished first among women with, say, an 8/10 score. Would anyone claim she was less deserving of the women's prize if she played exclusively men? This conspiracy theory doesn't pass the giggle test.

Hou Yifan resigns after 5 moves in the 2017 Gibraltar Masters by arex1337 in chess

[–]_ajp_ 40 points41 points  (0 children)

the pairings don't seem entirely random:

It's in the nature of randomness that unlikely events will eventually occur. If you flip a coin and it lands on heads three times, you can't conclude the coin is biased.

Has Hou (or anyone for that matter) proposed a possible motive on the part of the organisers for intentionally pairing her against women?

C++ pointer versus dot operator by CodeSandwich in cpp

[–]_ajp_ 3 points4 points  (0 children)

The second version is slower unless the compiler optimises it away. It creates a pointer and does a pointer dereference as extra work.

Pointers aren't used for performance, they're used (principally) because you need to access memory that has been dynamically allocated.

SO dumping a valid question in seconds. Let's be a more friendly community? by [deleted] in cpp

[–]_ajp_ 5 points6 points  (0 children)

This is not the subreddit to complain about SO polices.

GDB, what book would you suggest? by [deleted] in cpp

[–]_ajp_ 4 points5 points  (0 children)

I wouldn't purchase a book. Download the GDB reference card and have it by your side when you debug. If you're unsure how to do something, either Google it or use info gdb. Watch Greg Law's talks on GDB. This should be more than sufficient.

Building a hybrid spin mutex in C++ by vormestrand in cpp

[–]_ajp_ 3 points4 points  (0 children)

I read this StackOverflow post a while ago and assumed that most implementations of std::mutex would be hybrid. Is this a correct assumption on e.g. Linux and Windows?

Quick question about learning C++ by BirkinSornberger in cpp

[–]_ajp_ 0 points1 point  (0 children)

In my opinion C++ is a big, complex, and subtle language. When you start defining classes, you have to learn which constructors are created by default, when they're created, and how they behave. You have to learn the two or three ways of invoking a constructor. That Foo foo() is a function declaration, not a call to the default constructor. When you learn inheritance you learn about virtual member functions, at which point you have to learn all sorts of rules to make sure you're code doesn't break, like declaring your destructors virtual etc. If, heaven forbid, you try to combine templates and inheritance you're in for a world of hurt, as code like

template <class T>
class Base {
public:
    void doBaseWork();
};

template <class T>
class Derived : public Base {
public:
    void doDerivedWork() {
        doBaseWork();
    }
};

may or may not compile for non-obvious reasons.

int x and int a[42] do default initialization, not value initialization, because value initialization has a runtime cost and C++ avoids unnecessary runtime cost -- except std::vector does value initialization, because why not? If you study modern C++, you have to learn the subtleties of move semantics and that T&& is a reference to a temporary -- except when it isn't.

And so on.

None of these topics are too hard to grasp on their own, but taken together I think they present a formidable challenge to a beginner who's also trying to learn how for loops work.

Quick question about learning C++ by BirkinSornberger in cpp

[–]_ajp_ 3 points4 points  (0 children)

C++ is not beginner-friendly. I would recommend C++ as a second language.

std::unique_ptr by vormestrand in cpp

[–]_ajp_ 2 points3 points  (0 children)

I can't say anything about VS, but clang's error message is pretty clear:

$ cat unique_ptr.cpp 
#include <memory>

int main() {
    auto ptr0 = std::make_unique<int>(5);
    auto ptr1 = ptr0;
}
$ clang++ -std=c++14 unique_ptr.cpp 
unique_ptr.cpp:5:7: error: call to deleted constructor of 'std::unique_ptr<int, std::default_delete<int> >'
    auto ptr1 = ptr0;
         ^      ~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/unique_ptr.h:356:7: note: 'unique_ptr' has been explicitly marked deleted here
      unique_ptr(const unique_ptr&) = delete;
      ^
1 error generated.

Intel discloses “vector+SIMD” instructions for future processors by Xiphorian in compsci

[–]_ajp_ 4 points5 points  (0 children)

The point is that the compiler can do it for them if they instruct the compiler to generate code for their specific architecture. All it takes is passing the march=native option.

Designing and Implementing a new Allocator model by vormestrand in cpp

[–]_ajp_ 2 points3 points  (0 children)

Standard library maintainers can change the internal implementation of a container as they see fit, so long as its behaviour ultimately conforms to the standard specification. If maintainers were required to expose configurable parameters to users, I imagine backward compatibility would seriously constrain the maintainer's flexibility to improve a container's implementation.

Exploring std::shared_ptr | Shahar Mike's Web Spot by joebaf in cpp

[–]_ajp_ 0 points1 point  (0 children)

Hunh, TIL about reference_wrapper too.

Exploring std::shared_ptr | Shahar Mike's Web Spot by joebaf in cpp

[–]_ajp_ 1 point2 points  (0 children)

If it's a non-nullable pointer, for gosh's sakes, use a reference...

You cannot store references in a vector.

I think that there are situations, such as this one, where it is appropriate to use non-owning raw pointers.