Formatted output arithmetic inserters
Asked Answered
B

1

0

I have a basic question about the arithmetic inserters; § 27.7.3.6.2/1 [ostream.inserters.arithmetic]:

When val is of type bool, long, unsigned long, long long, unsigned long long, double, long double, or const void*, the formatting conversion occurs as if it performed the following code fragment:

bool failed = use_facet<
  num_put<charT,ostreambuf_iterator<charT,traits> >
    > (getloc()).put(*this, *this, fill(), val).failed()

The question is what exact function performs the conversion from a pointer to type to, as Matt McNabb corrected, const void*? For instance:

int *ip = new int(1);
std::cout << ip; //0xaa33fa67

I'm not concerned in an implementation details, I just would like to know what function produces arithmetic result from the pointer. Is it put in the example above?

Batruk answered 6/10, 2014 at 5:20 Comment(3)
The pointer is converted to const void *, not longDistributary
The conversion to const void * happens when the pointer is passed to operator<<(const void *).Benoit
I've undertood. ThanksBatruk
C
1

There's an implicit coversion from any non-pointer to member/member function to void*. After this is passed to the stream, it passes it off to std::num_put::put() which prints it out as a generic pointer as if by using the "%p" format flag.

Constrictor answered 6/10, 2014 at 12:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.