Specific use case of to_addressHow do I execute a command and get output of command within C++ using POSIX?Function passed as template argumentint a[] = 1,2,; Weird comma allowed. Any particular reason?Image Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionWhen should I really use noexcept?Why should I use a pointer rather than the object itself?Replacing a 32-bit loop counter with 64-bit introduces crazy performance deviationsenum to string in modern C++11 / C++14 / C++17 and future C++20Why do we require requires requires?Why std::overload instead of concepts/constexpr if in std::visit?
How did Avada Kedavra get its name?
What is the context for Napoleon's quote "[the Austrians] did not know the value of five minutes"?
My parents claim they cannot pay for my college education; what are my options?
Will users know a CardView is clickable
Why can't we feel the Earth's revolution?
Why is Skinner so awkward in Hot Fuzz?
How many times to repeat an event with known probability before it has occurred a number of times
Can I appeal credit ding if ex-wife is responsible for paying mortgage?
Threading data on TimeSeries
Approach sick days in feedback meeting
How to remove multiple elements from Set/Map AND knowing which ones were removed?
mathrm in LaTeX
How can Caller ID be faked?
SQL Server has encountered occurences of I/O requests taking longer than 15 seconds
How do I say what something is made out of?
...and then she held the gun
Are athletes' college degrees discounted by employers and graduate school admissions?
For Saintsbury, which English novelists constituted the "great quartet of the mid-eighteenth century"?
Are soroban (Japanese abacus) classes worth doing?
How do credit card companies know what type of business I'm paying for?
What should I be aware of in buying second-hand sinks and toilets?
Do legislators hold the right of legislative initiative?
Cant bend fingertip when finger is straight
Can an open source licence be revoked if it violates employer's IP?
Specific use case of to_address
How do I execute a command and get output of command within C++ using POSIX?Function passed as template argumentint a[] = 1,2,; Weird comma allowed. Any particular reason?Image Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionWhen should I really use noexcept?Why should I use a pointer rather than the object itself?Replacing a 32-bit loop counter with 64-bit introduces crazy performance deviationsenum to string in modern C++11 / C++14 / C++17 and future C++20Why do we require requires requires?Why std::overload instead of concepts/constexpr if in std::visit?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
So apparently C++20 is getting std::to_address.
From the cppreference page its use case doesn't seem clear to me. We already have operator& and std::addressof, why do we need yet another function that gives us an address to its argument?
c++ c++20 address-operator
|
show 3 more comments
So apparently C++20 is getting std::to_address.
From the cppreference page its use case doesn't seem clear to me. We already have operator& and std::addressof, why do we need yet another function that gives us an address to its argument?
c++ c++20 address-operator
10
All these obscure and "only 0.1% of programmers will ever use this" functions are getting accepted and added intostdbut we still have no networking library forstd, quite sad.
– Sombrero Chicken
Jun 7 at 11:48
Notes section provides an allocator example -std::addressofrequires the object to be already constructed.
– dewaffled
Jun 7 at 11:52
1
It's for C++ template metaprogramming, so both raw pointers and fancy pointers can be handled in the same way withstd::to_address.
– Eljay
Jun 7 at 11:52
2
@dewaffled I must've missed that. Basically just means it's yet another workaround function added to the standard to work around obscure standard rules that'd cause UB otherwise. Amazing. Cpp std is beginning to look like a circus
– Sombrero Chicken
Jun 7 at 11:55
3
stroustrup.com/P0977-remember-the-vasa.pdf
– Evg
Jun 7 at 11:56
|
show 3 more comments
So apparently C++20 is getting std::to_address.
From the cppreference page its use case doesn't seem clear to me. We already have operator& and std::addressof, why do we need yet another function that gives us an address to its argument?
c++ c++20 address-operator
So apparently C++20 is getting std::to_address.
From the cppreference page its use case doesn't seem clear to me. We already have operator& and std::addressof, why do we need yet another function that gives us an address to its argument?
c++ c++20 address-operator
c++ c++20 address-operator
edited Jun 7 at 20:57
curiousguy
4,91623046
4,91623046
asked Jun 7 at 11:44
Sombrero ChickenSombrero Chicken
26k33483
26k33483
10
All these obscure and "only 0.1% of programmers will ever use this" functions are getting accepted and added intostdbut we still have no networking library forstd, quite sad.
– Sombrero Chicken
Jun 7 at 11:48
Notes section provides an allocator example -std::addressofrequires the object to be already constructed.
– dewaffled
Jun 7 at 11:52
1
It's for C++ template metaprogramming, so both raw pointers and fancy pointers can be handled in the same way withstd::to_address.
– Eljay
Jun 7 at 11:52
2
@dewaffled I must've missed that. Basically just means it's yet another workaround function added to the standard to work around obscure standard rules that'd cause UB otherwise. Amazing. Cpp std is beginning to look like a circus
– Sombrero Chicken
Jun 7 at 11:55
3
stroustrup.com/P0977-remember-the-vasa.pdf
– Evg
Jun 7 at 11:56
|
show 3 more comments
10
All these obscure and "only 0.1% of programmers will ever use this" functions are getting accepted and added intostdbut we still have no networking library forstd, quite sad.
– Sombrero Chicken
Jun 7 at 11:48
Notes section provides an allocator example -std::addressofrequires the object to be already constructed.
– dewaffled
Jun 7 at 11:52
1
It's for C++ template metaprogramming, so both raw pointers and fancy pointers can be handled in the same way withstd::to_address.
– Eljay
Jun 7 at 11:52
2
@dewaffled I must've missed that. Basically just means it's yet another workaround function added to the standard to work around obscure standard rules that'd cause UB otherwise. Amazing. Cpp std is beginning to look like a circus
– Sombrero Chicken
Jun 7 at 11:55
3
stroustrup.com/P0977-remember-the-vasa.pdf
– Evg
Jun 7 at 11:56
10
10
All these obscure and "only 0.1% of programmers will ever use this" functions are getting accepted and added into
std but we still have no networking library for std, quite sad.– Sombrero Chicken
Jun 7 at 11:48
All these obscure and "only 0.1% of programmers will ever use this" functions are getting accepted and added into
std but we still have no networking library for std, quite sad.– Sombrero Chicken
Jun 7 at 11:48
Notes section provides an allocator example -
std::addressof requires the object to be already constructed.– dewaffled
Jun 7 at 11:52
Notes section provides an allocator example -
std::addressof requires the object to be already constructed.– dewaffled
Jun 7 at 11:52
1
1
It's for C++ template metaprogramming, so both raw pointers and fancy pointers can be handled in the same way with
std::to_address.– Eljay
Jun 7 at 11:52
It's for C++ template metaprogramming, so both raw pointers and fancy pointers can be handled in the same way with
std::to_address.– Eljay
Jun 7 at 11:52
2
2
@dewaffled I must've missed that. Basically just means it's yet another workaround function added to the standard to work around obscure standard rules that'd cause UB otherwise. Amazing. Cpp std is beginning to look like a circus
– Sombrero Chicken
Jun 7 at 11:55
@dewaffled I must've missed that. Basically just means it's yet another workaround function added to the standard to work around obscure standard rules that'd cause UB otherwise. Amazing. Cpp std is beginning to look like a circus
– Sombrero Chicken
Jun 7 at 11:55
3
3
stroustrup.com/P0977-remember-the-vasa.pdf
– Evg
Jun 7 at 11:56
stroustrup.com/P0977-remember-the-vasa.pdf
– Evg
Jun 7 at 11:56
|
show 3 more comments
1 Answer
1
active
oldest
votes
std::addressof takes an object and gets its address, even if unary "addressof operator" (aka &) was overloaded.
std::to_address takes a pointer, smart or dumb, and returns a pointer.
Basically when writing the std library, in this case allocators, implementors find they needed this utility function. It is small, simple, and has to be written whenever someone wants to work with allocators. So they wrote a no-brainer proposal to add it.
There are some traps here; you cannot do std::addressof(*ptr) because *ptr isn't always an object yet. There is already a trait that solves this, but writing code using traits directly is annoying.
Why this when they haven't finished your favourite feature? Like networking?
In comparison, networking is not a no-brainer proposal. And the current design depends on executors (basically abstractions of the concept of thread pools). The goal of writing a high level library that offers hand crafted C/ASM performance makes writing networking harder than a 2 line utility function.
Then somebody complains that they take 15 minutes to approve a no-brainer utility function, because the multiple programmer year epic proposal isn't in yet. The injustice.
Or something like that.
2
It's really smart to call plain pointers dumb ... well, isn't it?
– L. F.
Jun 7 at 12:19
Fair enough, I just don't understand why they need to add all these utilities that library writers want to use tostd. Just add it tostd::we_are_cool_lib_writersor something.
– Sombrero Chicken
Jun 7 at 12:35
6
@SombreroChicken The flip side is that if you don't specify that all these boring, implementation detail-ly, utility functions that are necessary to expressstd::interesting_thingas portable C++, people wanting to writeinteresting_thing_with_important_differencecomplain that they can't do whatstddoes. E.g.std::vectorneeds some magic to create an array from a bunch of adjacent objects, and that can't be replicated in user code.
– Caleth
Jun 7 at 13:09
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56493697%2fspecific-use-case-of-to-address%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
std::addressof takes an object and gets its address, even if unary "addressof operator" (aka &) was overloaded.
std::to_address takes a pointer, smart or dumb, and returns a pointer.
Basically when writing the std library, in this case allocators, implementors find they needed this utility function. It is small, simple, and has to be written whenever someone wants to work with allocators. So they wrote a no-brainer proposal to add it.
There are some traps here; you cannot do std::addressof(*ptr) because *ptr isn't always an object yet. There is already a trait that solves this, but writing code using traits directly is annoying.
Why this when they haven't finished your favourite feature? Like networking?
In comparison, networking is not a no-brainer proposal. And the current design depends on executors (basically abstractions of the concept of thread pools). The goal of writing a high level library that offers hand crafted C/ASM performance makes writing networking harder than a 2 line utility function.
Then somebody complains that they take 15 minutes to approve a no-brainer utility function, because the multiple programmer year epic proposal isn't in yet. The injustice.
Or something like that.
2
It's really smart to call plain pointers dumb ... well, isn't it?
– L. F.
Jun 7 at 12:19
Fair enough, I just don't understand why they need to add all these utilities that library writers want to use tostd. Just add it tostd::we_are_cool_lib_writersor something.
– Sombrero Chicken
Jun 7 at 12:35
6
@SombreroChicken The flip side is that if you don't specify that all these boring, implementation detail-ly, utility functions that are necessary to expressstd::interesting_thingas portable C++, people wanting to writeinteresting_thing_with_important_differencecomplain that they can't do whatstddoes. E.g.std::vectorneeds some magic to create an array from a bunch of adjacent objects, and that can't be replicated in user code.
– Caleth
Jun 7 at 13:09
add a comment |
std::addressof takes an object and gets its address, even if unary "addressof operator" (aka &) was overloaded.
std::to_address takes a pointer, smart or dumb, and returns a pointer.
Basically when writing the std library, in this case allocators, implementors find they needed this utility function. It is small, simple, and has to be written whenever someone wants to work with allocators. So they wrote a no-brainer proposal to add it.
There are some traps here; you cannot do std::addressof(*ptr) because *ptr isn't always an object yet. There is already a trait that solves this, but writing code using traits directly is annoying.
Why this when they haven't finished your favourite feature? Like networking?
In comparison, networking is not a no-brainer proposal. And the current design depends on executors (basically abstractions of the concept of thread pools). The goal of writing a high level library that offers hand crafted C/ASM performance makes writing networking harder than a 2 line utility function.
Then somebody complains that they take 15 minutes to approve a no-brainer utility function, because the multiple programmer year epic proposal isn't in yet. The injustice.
Or something like that.
2
It's really smart to call plain pointers dumb ... well, isn't it?
– L. F.
Jun 7 at 12:19
Fair enough, I just don't understand why they need to add all these utilities that library writers want to use tostd. Just add it tostd::we_are_cool_lib_writersor something.
– Sombrero Chicken
Jun 7 at 12:35
6
@SombreroChicken The flip side is that if you don't specify that all these boring, implementation detail-ly, utility functions that are necessary to expressstd::interesting_thingas portable C++, people wanting to writeinteresting_thing_with_important_differencecomplain that they can't do whatstddoes. E.g.std::vectorneeds some magic to create an array from a bunch of adjacent objects, and that can't be replicated in user code.
– Caleth
Jun 7 at 13:09
add a comment |
std::addressof takes an object and gets its address, even if unary "addressof operator" (aka &) was overloaded.
std::to_address takes a pointer, smart or dumb, and returns a pointer.
Basically when writing the std library, in this case allocators, implementors find they needed this utility function. It is small, simple, and has to be written whenever someone wants to work with allocators. So they wrote a no-brainer proposal to add it.
There are some traps here; you cannot do std::addressof(*ptr) because *ptr isn't always an object yet. There is already a trait that solves this, but writing code using traits directly is annoying.
Why this when they haven't finished your favourite feature? Like networking?
In comparison, networking is not a no-brainer proposal. And the current design depends on executors (basically abstractions of the concept of thread pools). The goal of writing a high level library that offers hand crafted C/ASM performance makes writing networking harder than a 2 line utility function.
Then somebody complains that they take 15 minutes to approve a no-brainer utility function, because the multiple programmer year epic proposal isn't in yet. The injustice.
Or something like that.
std::addressof takes an object and gets its address, even if unary "addressof operator" (aka &) was overloaded.
std::to_address takes a pointer, smart or dumb, and returns a pointer.
Basically when writing the std library, in this case allocators, implementors find they needed this utility function. It is small, simple, and has to be written whenever someone wants to work with allocators. So they wrote a no-brainer proposal to add it.
There are some traps here; you cannot do std::addressof(*ptr) because *ptr isn't always an object yet. There is already a trait that solves this, but writing code using traits directly is annoying.
Why this when they haven't finished your favourite feature? Like networking?
In comparison, networking is not a no-brainer proposal. And the current design depends on executors (basically abstractions of the concept of thread pools). The goal of writing a high level library that offers hand crafted C/ASM performance makes writing networking harder than a 2 line utility function.
Then somebody complains that they take 15 minutes to approve a no-brainer utility function, because the multiple programmer year epic proposal isn't in yet. The injustice.
Or something like that.
edited Jun 7 at 15:24
answered Jun 7 at 12:18
Yakk - Adam NevraumontYakk - Adam Nevraumont
193k21203398
193k21203398
2
It's really smart to call plain pointers dumb ... well, isn't it?
– L. F.
Jun 7 at 12:19
Fair enough, I just don't understand why they need to add all these utilities that library writers want to use tostd. Just add it tostd::we_are_cool_lib_writersor something.
– Sombrero Chicken
Jun 7 at 12:35
6
@SombreroChicken The flip side is that if you don't specify that all these boring, implementation detail-ly, utility functions that are necessary to expressstd::interesting_thingas portable C++, people wanting to writeinteresting_thing_with_important_differencecomplain that they can't do whatstddoes. E.g.std::vectorneeds some magic to create an array from a bunch of adjacent objects, and that can't be replicated in user code.
– Caleth
Jun 7 at 13:09
add a comment |
2
It's really smart to call plain pointers dumb ... well, isn't it?
– L. F.
Jun 7 at 12:19
Fair enough, I just don't understand why they need to add all these utilities that library writers want to use tostd. Just add it tostd::we_are_cool_lib_writersor something.
– Sombrero Chicken
Jun 7 at 12:35
6
@SombreroChicken The flip side is that if you don't specify that all these boring, implementation detail-ly, utility functions that are necessary to expressstd::interesting_thingas portable C++, people wanting to writeinteresting_thing_with_important_differencecomplain that they can't do whatstddoes. E.g.std::vectorneeds some magic to create an array from a bunch of adjacent objects, and that can't be replicated in user code.
– Caleth
Jun 7 at 13:09
2
2
It's really smart to call plain pointers dumb ... well, isn't it?
– L. F.
Jun 7 at 12:19
It's really smart to call plain pointers dumb ... well, isn't it?
– L. F.
Jun 7 at 12:19
Fair enough, I just don't understand why they need to add all these utilities that library writers want to use to
std. Just add it to std::we_are_cool_lib_writers or something.– Sombrero Chicken
Jun 7 at 12:35
Fair enough, I just don't understand why they need to add all these utilities that library writers want to use to
std. Just add it to std::we_are_cool_lib_writers or something.– Sombrero Chicken
Jun 7 at 12:35
6
6
@SombreroChicken The flip side is that if you don't specify that all these boring, implementation detail-ly, utility functions that are necessary to express
std::interesting_thing as portable C++, people wanting to write interesting_thing_with_important_difference complain that they can't do what std does. E.g. std::vector needs some magic to create an array from a bunch of adjacent objects, and that can't be replicated in user code.– Caleth
Jun 7 at 13:09
@SombreroChicken The flip side is that if you don't specify that all these boring, implementation detail-ly, utility functions that are necessary to express
std::interesting_thing as portable C++, people wanting to write interesting_thing_with_important_difference complain that they can't do what std does. E.g. std::vector needs some magic to create an array from a bunch of adjacent objects, and that can't be replicated in user code.– Caleth
Jun 7 at 13:09
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56493697%2fspecific-use-case-of-to-address%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
10
All these obscure and "only 0.1% of programmers will ever use this" functions are getting accepted and added into
stdbut we still have no networking library forstd, quite sad.– Sombrero Chicken
Jun 7 at 11:48
Notes section provides an allocator example -
std::addressofrequires the object to be already constructed.– dewaffled
Jun 7 at 11:52
1
It's for C++ template metaprogramming, so both raw pointers and fancy pointers can be handled in the same way with
std::to_address.– Eljay
Jun 7 at 11:52
2
@dewaffled I must've missed that. Basically just means it's yet another workaround function added to the standard to work around obscure standard rules that'd cause UB otherwise. Amazing. Cpp std is beginning to look like a circus
– Sombrero Chicken
Jun 7 at 11:55
3
stroustrup.com/P0977-remember-the-vasa.pdf
– Evg
Jun 7 at 11:56