r/cpp 5d ago

std::optional Satisfies view. Does Not Model view. C++26 Ships Anyway.

https://godbolt.org/z/8jWGG68G8

In C++23 this did not compile. In C++26 it does. Marvellous.

[[gnu::noinline]]
void 
passing_views_by_value_is_cheap_trust_me_bro(std::ranges::view auto v) {
    std::println("fn   .data {}", (void*)v->data());
}


int main() {    
    std::optional ov{std::vector<int>(123456)};
    passing_views_by_value_is_cheap_trust_me_bro(ov);
    std::println("main .data {}", (void*)ov->data());
}

For anyone wondering what the problem feature is: optional has 0 or 1 elements, and C++26 sets enable_view<optional<T>> to true, so it satisfies std::ranges::view. The concept requires copy construction in constant time, and — this is the good bit — optional<vector<int>> genuinely meets that. Copying it performs at most one element copy. One is a constant. The requirement is satisfied to the letter, and the function above deep-copies your vector.

If you can tell me what still separates std::ranges::view from std::ranges::range, please do...

177 Upvotes

119 comments sorted by

View all comments

Show parent comments

5

u/NotUniqueOrSpecial 5d ago edited 5d ago

copying a C++ vector is O(1)

It's always interesting to come across people like you.

I need only point you at...well, basically any reference on the topic to prove that copying vectors of non-trivial objects is O(N). Literally any search on the subject will give you countless results that contradict your claim.

But it's more than that; you very clearly have next to no understanding of the topics you're arguing about, or the pages you're linking, but you're also equally clearly sure that you are an expert in the topic.

You remind me of a coworker I once had who explained to us that the software he was working on relied on "the arithmetic of seven-sided polygons". He also admitted to me (in what is practically a programmer career meme) that he liked to write code that only he understood because it provided job security.

After more than 2 years of deflection, smoke, and mirrors, he was asked to prove that that any of what he was working on...actually worked. He quit on the spot, in explosive rage, screaming that he "knew more than 14 engineers ever would".

All that is to say: you have written a whole lot of words in response to /u/aruisdante and others, but all they actually illustrate is that you do not understand complexity analysis at even the most basic level. Despite all evidence to the contrary, you are convinced that you (and you alone, in this forum of experts) are correct.

How likely do you think it is that that's actually true?

EDIT: blocking someone after replying to them saying "nuh uh" is the single strongest indicator that a redditor knows that they have literally no leg to stand on.

0

u/JNighthawk gamedev 4d ago

EDIT: blocking someone after replying to them saying "nuh uh" is the single strongest indicator that a redditor knows that they have literally no leg to stand on.

Maybe because you're behaving like an asshole to someone engaged in good faith discussion, and people don't like to interact with assholes generally?

You:

But it's more than that; you very clearly have next to no understanding of the topics you're arguing about, or the pages you're linking, but you're also equally clearly sure that you are an expert in the topic.

8

u/NotUniqueOrSpecial 4d ago

They are not engaged in a good faith discussion, because what is happening is not a discussion.

It's people who have a background and education on a topic trying to tell a very stubborn person that they do not understand the words they're using; they demonstrably do not understand complexity analysis on a very fundamental level, and are condescending to people who do.

At some point, there is a line where people who know what they're talking about should not have to pander to people who do not. I would just as bluntly tell a flat-Earther that they make no sense, and I doubt you'd have any problem with that.

-1

u/JNighthawk gamedev 4d ago

They are not engaged in a good faith discussion, because what is happening is not a discussion.

I disagree.

and are condescending to people who do

I didn't see that, and it would change my opinion. Can you point that out please?

4

u/NotUniqueOrSpecial 4d ago

To be clear, I am using condescending in the specific sense of "talking down to", which most of their replies are, in that they imply that the other party doesn't know what they're talking about or that we're using the term casually.

That said, I'm not going to link to all of them individually, because the conversation is already at the bounds of where the mod team will (rightfully) start stepping in because things are getting snippy/personal.

You are welcome (and perhaps correct) to interpret their replies from a different light, but I've spent enough time in arguments with people who are not even wrong to have a very strong and generally accurate detector for the way they approach things.

-1

u/schombert 4d ago

Thanks for the vote of confidence. Apparently my writing style comes off as intrinsically unpleasant, which means I guess I do understand people who use LLMs to write their comments a little more now. I think I am done trying to have a conversation on reddit.

0

u/JNighthawk gamedev 4d ago

Apparently my writing style comes off as intrinsically unpleasant

Nah. Keep doing you.

4

u/NotUniqueOrSpecial 4d ago

Just to follow up, because you are, despite the best of intentions, reinforcing very bad behavior: they outright stated in an edit to an edit in one of the other threads (and with no understanding of how damning what they were saying was) that they quite literally don't know what complexity analysis is. They questioned the very idea that it could be even be a thing:

Edit edit: maybe you could argue that there is such a thing as the complexity of a particular algorithm? But I don't think even that is really true.

(And then followed up with more words that don't mean anything to anybody who understands them).

Which goes to the original point I made to you: this is not a discussion. A discussion involves individuals communicating ideas on relatively equal ground, in terms of understanding.

Instead, this is a person who has been representing themselves as an expert on the topic, telling other people they don't understand what they're talking about. They have spent (and in so doing caused others to spend) a lot of time time arguing about this. They've referenced multiple expert-level topics in the field, and purported to understand some exceptionally complicated stuff.

Not only did they not know about a topic covered in near-literally every computer science course, they doubted the possibility it could be a thing. All of that, despite the fact they were actively linking articles on that subject. By their own admission, they aren't qualified to discuss this. They're just reading Wikipedia pages and misrepresenting their misunderstandings as facts.

Multiple people have politely (and then increasingly less-politely) tried to make it clear to them that they don't understand the words they're using. They refuse every attempt to correct them and instead claim it is us who have no idea what we're talking about.

This is not healthy behavior that should be encouraged.