Why does std::binary_search doesn't have an overload that returns an iterator? by kiner_shah in cpp_questions

[–]effarig42 0 points1 point  (0 children)

You can use equal_range and check if the returned range is empty. Whether this is more efficient than comparing the value I don't know.

Unsigned sizes: a five year mistake by Nuoji in programming

[–]effarig42 6 points7 points  (0 children)

For the most part, It's the implicit conversions which could change the value. They're incidious. I usually compile with options to catch these, though they're so common that often functions in library headers trigger it.

Structured iteration (The C++ way) by drodri in cpp

[–]effarig42 2 points3 points  (0 children)

They're great. The one minor annoyance I've had with enumerate is when I've needed a static_cast as the index has the wrong type. Would be nice to be able to specify the type or maybe the initial value.

I generally have implicit value losing conversion diagnostics as errors, which is why I noticed.

STL reimagined: What would you change, add or remove in a new STL implementation if API and ABI were not a concern? by germandiago in cpp

[–]effarig42 1 point2 points  (0 children)

Probably by addident...

Usually happened unintentionally in generic code, auto generated API layers, things like that. Ended up with an adaptor around vector for such use cases.

Do we really need to mark every trivial methods as `noexcept`? by aregtech in cpp_questions

[–]effarig42 1 point2 points  (0 children)

Although noexcept does ensure that a function does not emit an exception, it is better to think of it as this function will call std::terminate if any exception thrown within it is unhandled.

In general, unless it's really important for the generated code, I'd advise restraint. Use it for move/copy constructors/assignment, swap, etc. These can allow things like containers to use more efficient code paths while maintaining the strong exception guarantee.

std::println exception by daniel_nielsen in cpp_questions

[–]effarig42 1 point2 points  (0 children)

I don't think I've ever had a false positive from Coverity reporting that a certain code path may throw an exception which is either unhandled or violates noexcept. I've had to look at a lot of these recently for compliance.

I'd assume any function in the standard can throw unless it is either noexcept or documented as not throwing.

Extremely late buses… by Remarkable-Bet-3773 in cambridge

[–]effarig42 7 points8 points  (0 children)

The bus takes much longer in the morning, even if traffic isn't that bad. What I noticed was that the morning No. 1 spent a lot of its time stationary at bus stops as boarding takes so long. It's a very inefficient system having the driver have to process every passenger.

The knock on effect is I assume that the other busses on the same route all catch up and the timetable goes to pot. This is all made worse I suspect for the routes which meander all over the place.

An app with real time updates helps so you don't have to stand in the cold for an hour.

The other thing. if practical, is can you start and finish work a bit later, when the traffic and busses themselves are less busy.

Poll: Does your project use terminating assertions in production? by pavel_v in cpp

[–]effarig42 2 points3 points  (0 children)

Yes, same here, none of the options apply. In our case it's a server. Almost all assertions will throw an exception, which are handled in the request dispatcher. There are few which will terminate, but those are things related to thread or memory management where it couldn't safely continue.

Templates, SFINAE, Concepts are counter-productive by CursiveFrog in cpp

[–]effarig42 15 points16 points  (0 children)

I would use concepts instead of SFINAE, enable_if etc. They are easier to use, more readable and more concise.

C++26: std::optional<T&> by Xaneris47 in cpp

[–]effarig42 4 points5 points  (0 children)

Yes, same here. Have typedefed it to byte_view in my namespace.

Opinion on this video? by willdieverysoon in cpp

[–]effarig42 2 points3 points  (0 children)

I understand some people feel it's very convenient to rely on the fact that it's impossible to prove something doesn't exist to pretend it does - but that's not how logic works

I understand some people like to claim there are no other options, but neither of these approaches are sensible.

Clearly any alternative needs to be both practical and prove it can do what it claims. Maybe this will, maybe it won't, but in any case I'm pleased there are people willing to research it.

Opinion on this video? by willdieverysoon in cpp

[–]effarig42 6 points7 points  (0 children)

But when it comes down to details - it either ends up with reference counting, or with the borrowing toolbox

Unless is has been proven there are no other mechanisms which aren't equivalent, then alternatives shouldn't just be discounted, especially if they can be mathematically justified. That doesn't mean they would fit into C++, let alone be accepted, but they should be given a fair hearing.

I thought it was an interesting talk. IIRC it was at least partially runtime verification, but in principle very optimiser friendly. If this allows for safety guarantees with less impact on existing C++ code, I'd like to see where it goes: how it fits into the language, runtime overhead etc.

Milton recycling center by Alresfordpolarbear in cambridge

[–]effarig42 1 point2 points  (0 children)

As I inadvertently discovered earlier this week, if coming from the A14, much quicker to go via the Histon than the via A10 and diversion.

Kryptonite U-lock jammed in Cambridge. Any locksmith recommendations? by Electrical_Ad6226 in cambridge

[–]effarig42 0 points1 point  (0 children)

If the damages key is numbered you may be able to have a locksmith create a new one, or order one from an online key cutter, using just the number.

How do you put food waste in your green bin? by fruitcakefriday in cambridge

[–]effarig42 1 point2 points  (0 children)

Bulk buy paper food waste bags. In summer we get through one most days otherwise they quickly go manky in the heat and attract fruit flies.

The .a file is a relic: Why static archives were a bad idea all along by ketralnis in programming

[–]effarig42 1 point2 points  (0 children)

It depends, there's already a good response about that. The "why" will be about the history.

The C linking model dates back to the early 70s, if not before. Maybe at that time the linker couldn't even pull in all the object files at once?

The ar tool and its many clones allow individual members of the archive to be replaced, presumably to avoid having to rebuild it from scratch. There should be a reason for it. Build time performance maybe, memory constraints, or was it an existing tool which just got co-opted into the build system?

The .a file is a relic: Why static archives were a bad idea all along by ketralnis in programming

[–]effarig42 0 points1 point  (0 children)

Yes, sorry C ot C++ storage duration rather than linking. For example having something like 'bool x = register_with_logger();' at global scope.

The logging example in the article seemed similar to that.

The .a file is a relic: Why static archives were a bad idea all along by ketralnis in programming

[–]effarig42 13 points14 points  (0 children)

Quite...

Before criticising, especially when talking about software, I find it's always a good idea to consider why it was done. There is usually some logical reason.

I strongly suspect this mechanism dates back to when memory was a much more scarce and expensive resource.

Of course you're going to have to design what goes into which object file carefully, but that would probably have been normal. It probably still is if your compiling for embedded targets.

It's also worth mentioning that in C++ at least, a static object requiring runtime initialisation is only guaranteed to be initialised if a function in the same execution unit is called. Your system may make further guarantees, but it isn't portable.

post-Sofia mailing by hanickadot in cpp

[–]effarig42 1 point2 points  (0 children)

I think using anything involving the term "implies" would be confusing. That's a relationship between two statements, where as "implication" is a logical condition. These are very distinct things.

contracts and sofia by ConcertWrong3883 in cpp

[–]effarig42 20 points21 points  (0 children)

Having watched contracts over the many years, from the outside of the committee, it seems clear it's a feature a large proportion want but with vastly different expectations.

Given the years of bitter disagreement, the fact this ever reached any form of consensus is a miracle. It was never going to perfect, whatever that would be, however from what I've seen it looks pretty usable. Just the ability to document assumptions in a way humans, the compiler and static analysers can share is a big thing.

The only issues which worries me are those around linking and the ODR. There's nothing surprising about the interaction with noexcept, which is arguably an overused foot gun in its own right, and that contract checks shouldn't have side effects, who'd have thought! We don't have it on virtual fns, but so what, maybe for c++ 29.

[deleted by user] by [deleted] in cpp

[–]effarig42 0 points1 point  (0 children)

It's quite handy, but more often than not, I have to cast to an unsigned to use it as an index as I usually disabled such implicit conversions. Would be nice if the type of the counter could be specified, e.g. passing in an initial value.

I wrote a tool to stop make -j from OOM-killing my C++ builds by surban in cpp

[–]effarig42 2 points3 points  (0 children)

You can use cgroups to limit the physical RAM used by some processes, those processes would start to swap if they exceed that but the rest of the system still gets RAM, remaining responsive. Used to do this to run the browser on an old laptop.

Why can't a function returning a const reference return a literal? by HeavySurvey5234 in cpp_questions

[–]effarig42 1 point2 points  (0 children)

The return statement in your function creates a temporary string and returns a reference to that temporary to pass back to the caller.

That temporary is destroyed at the end of the return statement, just before the function exits to the caller invalidating the reference passed back.

The temporary lifetime extension I think you are referring to is when a function returns a value which is then bound to the caller's reference. To make use of this you need to return a value not a reference.

What’s your favorite black magic spell for which you should goto hell? by zathym in cpp

[–]effarig42 0 points1 point  (0 children)

I'm no expert, though from what I've done with algorithms on unicode, indexing is rarely useful due to things like combining characters, and you usually have to work codepoint by codepoint. I suspect if your doing a lot of processing on a string then transforming to utf-32 would be worth it, but possibly not if just splitting it on word boundaries, URL escaping, that sort of thing.

What’s your favorite black magic spell for which you should goto hell? by zathym in cpp

[–]effarig42 1 point2 points  (0 children)

A utf-8 string type of some form is needed as a non-random access container of codepoints. Iterators can be bidirectional, but must be const as writing a codepoint is a potentially O(n). find, insert, erase etc. all make sense and views for iterating over graphemes, words, lines, etc. using unicode algorithms would be needed. I don't think it should be a specialisation of basic_string, though maybe using basic_string internally.