Do you use C++11

Pages: 1... 45678
closed account (zb0S216C)
LB wrote:
"A whole class for a simple function, obscuring syntax and adding complexity? If I didn't know you were being serious, I'd use that word you don't like."

It's called a "functor".

LB wrote:
"Both varieties give the same level of control"

Can you jump ahead or jump backwards in a RBF? No, so the level of control is in fact not the same -- less in fact, as I said previously.

LB wrote:
"I've been working with the traditional for loops for years now and they still look obscure."

Then you're doing something wrong. All of my loops are more readable because of my conventions.

LB wrote:
"but you have to think and figure out what it actually does."

That's why comments exist.

Wazzak
Framework wrote:
Can you jump ahead or jump backwards in a RBF? No, so the level of control is in fact not the same -- less in fact, as I said previously.
You can, but you shouldn't use a for loop for this kind of activity.

Framework wrote:
Then you're doing something wrong. All of my loops are more readable because of my conventions.
Conventionalize this:
1
2
3
4
for(MyContainer_t::const_iterator it = MyContainer.begin(); it != MyContainer.end(); ++it)
{
    //...
}


Framework wrote:
That's why comments exist.
Comments display intent and why choices were made, code displays what actually happens.
Checkmate, LB!
1
2
3
4
5
6
7
8
typedef MyContainer_t::const_iterator It;
#define BEGIN MyContainer.begin()
#define END MyContainer.end()

for (It it = BEGIN; it != END; ++it)
{
    // ...
}


L B wrote:
"A whole class for a simple function, obscuring syntax and adding complexity? If I didn't know you were being serious, I'd use that word you don't like."
Framework wrote:
It's called a "functor".

That's the word you don't like?
It's called a "functor".
Let's say I am creating templated function do_something_with_container(Container& T)
It should iterate from the beginning to the end.
I will ship it to the customer. He might use it with arrays.
How the hell will you use functor saving transparency of use and without using std::begin/end?

Another example I posted before: there is container you cannot change and which doesn't provide begin/end functions. You should make it work with your function without any code duplication and without changing function signature. What will you do in this case?
Last edited on
closed account (zb0S216C)
LB wrote:
"You can, but you shouldn't use a for loop for this kind of activity."

No? What should you use, then?

LB wrote:
"Conventionalize this:"

That example is fine with me; there's no need to change it.

LB wrote:
"Comments display intent and why choices were made"

Any comment is useful so long as it has meaning and context.

LB wrote:
"That's the word you don't like?"

No.
@LB
Save your breath
from Framework's profile:
Things to note:
- I don't like using pre-made libraries (unless I'm the one who wrote it)
- I almost never use the Standard C++ Library; it's terrible.
- I like to work on the lowest-possible level
- I'm a narcissist, and I know it
Emphasis added.
Last edited on
I give up. Catfish: die in a fire. Framework: don't teach anyone C++. MiiNiPaa: Teach everyone C++. Me: Don't engage Framework again.
Last edited on
Only if Fredbill30 and devonrevenge join me.
Catfish4 wrote:
Only if Fredbill30 and devonrevenge join me.
Deal.
Tonight we derail in hell!

I spy with my little eye, a triplicate feature!
http://en.cppreference.com/w/cpp/container/dynarray

So when are we doing to have std::matrix? Serious question.
Catfish4 wrote:
So when are we doing to have std::matrix? Serious question.
In C++17 probably.
Yeah, for those that don't know, C++14 is planned to be a bugfix release like C++03 was, and C++17 is planned to be the next major additions release of C++.
Reading http://www.meetingcpp.com/index.php/br/items/a-look-at-cpp14-papers-part-1.html I found out following sentence:
This problem was discovered, when a different paper was being prepared, proposing more then one dimension for std::array
If it will be supported for std::array, it will probably will be supported for std::dynarray.
Two dimensional dynamic arrays + some functions to manipulate them = matrix. It is close.

Also: does anybody uses valarray? It might be useful to implement vectors for example (in mathematical sense) or, using slice and gslice, dynamic multidimensional arrays, but it looks too obscure to use it directly.
I love valarrays because, in popular implementations, they give you expression templates without any boilerplate (try that in Java!), but when I need to do something with a matrix, I end up using a matrix library (boost.ublas, eigen, etc), for the functionality.
Do I use C++11? Nope. Not even looked at what the C++11 implementation added.
Are you trying to impress us, BHXSpecter?

Also: does anybody uses valarray? It might be useful to implement vectors for example (in mathematical sense) or, using slice and gslice, dynamic multidimensional arrays, but it looks too obscure to use it directly.

I think I'm going to suggest std::valarray to beginners instead of std::list or std::vector, of course only when the usage scenario is appropriate.

As for me, I haven't had the chance (or desire) to use std::valarray yet, but it does look good. Maybe it can be used to manipulate OpenGL matrices? Then copy their contents back to a contiguous container such as std::vector?
Catfish4 wrote:
Are you trying to impress us, BHXSpecter?

Sarcasm aside, nope, just suck enough at programming that I don't see the point in learning more things I won't end up using in my code for lack of understanding it.
closed account (1yR4jE8b)
You're not going to get better with that attitude.
closed account (o1vk4iN6)
Let's say I am creating templated function do_something_with_container(Container& T)


That's probably why you don't see any standard C++ functions simply pass a container, the better option would be for the function to simply take iterators.

Using functors it would just be something like this:

1
2
3
4
5
6
7
8
9
10

template <typename C>
class BeginFunctor
{
public:
    typename C::iterator operator() (C& c) const { return c.begin(); }
};

template <typename C, typename B = BeginFunctor<C>, typename E = EndFunctor<C>>
void do_something_with_container(C& T, const B& b = B(), const E& e = E());


Though std::begin/end would probably be the better choice to go as it is already provided and probably the better solution to supporting range based for loops than having a clashing naming convention in the container itself.

"That's the word you don't like?"


The word he doesn't like is "trolling" and it seems to be a word people jump to because they don't know how to handle a discussion disputing over some subject. If anything "stubborn" is a better suited word.
Last edited on
That's probably why you don't see any standard C++ functions simply pass a container
That actually because function taking two iterators is more general (you can apply it to only part of the container). I would love if standard algorithms would have overload taking container: std::sort(myVector, absoluteValue()); instead of std::sort(myVector.begin(), myVector.end(), absoluteValue());. We use helper function with these signatures and it really improves code readability.

Using functors it would just be something like this:
It should work with arrays transparently to customer. He shouldn't do anything to make it work with arrays.
Last edited on
Pages: 1... 45678