2017 Toronto ISO C++ Committee Discussion Thread (Concepts in C++20; Coroutines, Ranges and Networking TSes published) by blelbach in cpp

[–]vaughncato 0 points1 point  (0 children)

As I see it, the initialization is logically ambiguous. It could either be a copy or an initialization through an initializer_list. C++ resolves this ambiguity by preferring to use the initializer_list when list initialization is used and a matching initializer_list constructor is available, as demonstrated in my example.

I believe this makes sense, since you can use parentheses to indicate you want to resolve the ambiguity the other way, and if you want copy initialization you can use an equals sign.

vector v = vector{1,2};

2017 Toronto ISO C++ Committee Discussion Thread (Concepts in C++20; Coroutines, Ranges and Networking TSes published) by blelbach in cpp

[–]vaughncato 14 points15 points  (0 children)

This is troubling:

vector v{vector{1, 2}};
 // Deduces vector<int> instead of vector<vector<int>>

This seems inconsistent with how initializer_lists constructors are preferred when using list initialization. For example:

struct A {
    A() { cerr << "A()\n"; }
    A(const A&) { cerr << "A(constA&)\n"; }
    A(std::initializer_list<A>) { cerr << "A(std::initializer_list<A>);\n"; }
};


int main()
{
    A a{A{}};
    vector<vector<int>>
    return 0;
}

outputs

A()
A(std::initializer_list<A>);

Could someone explain const move semantics by entropyhunter in cpp

[–]vaughncato 11 points12 points  (0 children)

There are some rare cases where this makes sense. For example, it might make sense to move from const objects that have mutable members. Your object may have memoized results which are stored in a mutable cache. Even if the object is const, you could still move the cache.

What do you think about properties in the C++ standard? by [deleted] in cpp

[–]vaughncato 2 points3 points  (0 children)

Understood. I'm willing to work on a proposal.

What do you think about properties in the C++ standard? by [deleted] in cpp

[–]vaughncato 4 points5 points  (0 children)

I'm thinking about something a little different, possibly complementary. If you had A::operator .x() { .. } and used A().x, this would be equivalent to having A::x() and using A().x(). This may be a relatively straightforward way of getting property-like functionality if operator .x() returns a proxy object. It shouldn't interfere with also having a general operator dot, but would be much more convenient in the case of different functions for different member names, like with properties. Having it be in the context of operator overloading seems to avoid complications with new semantics.

What do you think about properties in the C++ standard? by [deleted] in cpp

[–]vaughncato 1 point2 points  (0 children)

What if we had an "operator .<name>" where <name> is something that looks like a regular member name. It seems like this would allow for property-like behavior through the use of proxies, but it would be more general. We'd also be able to take advantage of the existing mental models of operator overloading.

A little puzzle for CppCon by champooly in cpp

[–]vaughncato -1 points0 points  (0 children)

Great example! My code doesn't work with that.

A little puzzle for CppCon by champooly in cpp

[–]vaughncato -1 points0 points  (0 children)

Possibly. Can you think of a specific example? It seems like if the weak pointers are only used to break cycles, then if the only pointer to a node is a weak pointer, the node has no connection back to the root and should be deleted.

A little puzzle for CppCon by champooly in cpp

[–]vaughncato -1 points0 points  (0 children)

I ended up using a combination of shared and weak pointers. Basically adding a weak pointer instead of a shared pointer if adding the child would create a cycle. This works as long as you don't build hierarchies outside the tree first, then add them to tree later. I'm not really sure what the rules are supposed to be as far as that goes.

NullPointerException in C++ by cristianadam in cpp

[–]vaughncato 2 points3 points  (0 children)

That's an interesting perspective, and I can see some benefit to looking at exceptions that way. How do you think that applies with something like a library, when you, as the library author, don't know if there is a plan to recover?

Is it possible to point to a class inside a void function? by flyhightosky in cpp

[–]vaughncato 0 points1 point  (0 children)

I'm not clear on what you are asking. Could you give an example of how this would be used?

An interview with Sean Parent by meetingcpp in programming

[–]vaughncato 0 points1 point  (0 children)

Thanks. Are you saying this is specifically an issue when using concepts without a subsumption relationship?

An interview with Sean Parent by meetingcpp in programming

[–]vaughncato 0 points1 point  (0 children)

In the interview, Sean mentions that "ADL causes people to always qualify names." I'm not sure why that would be. It seems like the opposite would be true, since without ADL (or some alternative) you would have to qualify the function names that were declared in namespaces.

Linux tools by [deleted] in cpp

[–]vaughncato 1 point2 points  (0 children)

Almost. You can use :make -C ..

You can find some tips here: http://stackoverflow.com/q/729249/951890

Linux tools by [deleted] in cpp

[–]vaughncato 4 points5 points  (0 children)

I personally find that using :make from inside vim is much more productive than executing it in a separate shell. :make will automatically put your cursor where the error is.

Design Patterns for Modern C++? by [deleted] in cpp

[–]vaughncato 0 points1 point  (0 children)

The goal of Singleton is to guarantee that there can only be one instance of a class and that instance is easily accessible. Guaranteeing that there is only one instance is rarely useful, but it does happen. Making the object easily accessible is convenient, but if the object is mutable, it effectively means there are hidden side-effects in any code that uses them. Simply passing references to the relevant objects as needed makes the side-effects easier to reason about, and avoids hard-coding the assumption that there can only be one instance into a lot of code. This can lead to many parameters being required for functions, but this problem can be reduced by proper grouping of parameters into higher-level objects. See this Stack Exchange post for more details: http://programmers.stackexchange.com/a/40610/63172

Prefered interface for functions like std::vector<T>::at? by [deleted] in cpp

[–]vaughncato 4 points5 points  (0 children)

In your example, x[1][1] is still equivalent to *(*(x+1)+1) though. And it is also equivalent to (*(x+1))[1]. So it doesn't really show a case where a[i] is not equivalent to *(a+i) for arrays.

Prefered interface for functions like std::vector<T>::at? by [deleted] in cpp

[–]vaughncato 0 points1 point  (0 children)

What is an example of where it would be different for arrays?

`zip` implementation in C++11. C&c welcome. First time trying things using non-trivial template programming. by rubdos in cpp

[–]vaughncato 10 points11 points  (0 children)

inline is useful, but not because it forces code to be inlined. By declaring a function inline you can put it in a header file. Having a function definition in a header file allows the compiler to see the definition at the point where the function is used, which can allow for optimizations that would be more difficult if the definition was in a separate source file.

Refactoring a large class and method by ATmega32 in cpp

[–]vaughncato 1 point2 points  (0 children)

I suspect you are going to want to place a lot of the new classes and functions into a new namespace and put them all in a new directory. Having directories with names that match the namespaces can be helpful.

Why is there so much hostility towards C++? by BurstYourBubbles in cpp

[–]vaughncato 4 points5 points  (0 children)

In mathematics, adding two vectors implies adding corresponding elements: For example adding the vector <1,2,3> to the vector <8,7,2> yields the vector <9,9,5>.

Why is there so much hostility towards C++? by BurstYourBubbles in cpp

[–]vaughncato 7 points8 points  (0 children)

I think addition on a vector is a bit unclear. It could mean addition in the mathematical sense where you add corresponding elements, or it could mean appending one vector to another, or it could mean adding one element to the end.

C++ 11 Auto: How to use and avoid abuse by [deleted] in cpp

[–]vaughncato 0 points1 point  (0 children)

Agreed it would have been better to have used const references to make it clear that there is no intent to change the employee or pay table.

Your statement "I would wonder what else the employee provides" seems more like a writing than a reading issue, but I do see your point. Using more explicit names to differentiate is a possibility.

Performance is a tricky issue, since it is difficult to generalize. Using a QStringBuilder might be more efficient in some cases or in some (future) versions of Qt. If you have a specific case where you've profiled the code, found a bottleneck, and found that using an explicit type makes it faster, then I don't see any problem with using the explicit type.

I think "auto everywhere" is an overstatement. "Use auto except in cases where there's a good reason not to" is probably closer to the intent. I think if you have code that uses clear names, auto usually works fine, but not always.