C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Function only accepts parameter that will persist

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Tue, 30 Apr 2024 17:30:48 +0200
That would possibly be function overload resolution at runtime? (You suggested different function parameter types and overloads for storing into a map.) It could also possibly lead to failed overload resolution only detected at runtime?     -----Ursprüngliche Nachricht----- Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Di 30.04.2024 16:05 Betreff:Re: [std-proposals] Function only accepts parameter that will persist An:std-proposals_at_[hidden]; CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>; On Tue, Apr 30, 2024 at 3:01 PM I wrote: > > But maybe we need some sort of class that has the option of copying > the object, something like this: > >     https://godbolt.org/z/rz6dfvGPo Just one other thing I want to mention . . . In the following constructor:    String(char const *const arg) noexcept(false)    {        std::cout << "copying\n";        p = new char[ std::strlen(arg) + 1u ];        should_delete = true;        std::strcpy( const_cast<char*>(p), arg );    } You could check if 'arg' points to a page of memory that is read-only. If it's read-only then use the non-copying constructor instead. On MS-Windows, 'VirtualProtect' gives us this info. On Linux, 'mprotect' give us this info. On a microcontroller, check if the address is in the range 0x0 - 0x2000 (i.e. read-only ROM), or from 0x2000 onwards (i.e. volatile RAM). -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-04-30 15:30:53