Performs std :: istringstream :: imbue on its own passed object

I am using Boost to convert a date of the form "01-Jan-2000" to a Julian number. The way I do it, use

int toJulian(std::string date)
{
    std::locale loc = std::locale(std::locale::classic(), new boost::posix_time::time_input_facet("%d-%b-%Y"));
    std::istringstream ss(date);
    ss.imbue(loc);
    boost::posix_time::ptime p;
    ss >> p;
    return p.date().julian_day();
}

      

(This is according to the examples in the Boost documentation).

But it's not clear to me if it is a memory leak or not. I have no explicit one delete

. Obviously, if the imbue

ownership of the pointer is transferred to the loc

stream, then it is possible that it is removed when it ss

goes out of scope.

Am I correct?

See http://www.boost.org/doc/libs/1_43_0/doc/html/date_time/date_time_io.html#date_time.format_flags

+3


source to share


1 answer


Short answer: No, but the std :: locale object does .

You want to look at http://en.cppreference.com/w/cpp/locale/locale/locale

You are calling the constructor (overload 7)

template< class Facet >
locale( const locale& other, Facet* f );

      



The linked link is clear:

Overload 7 is usually called with its second argument, f, derived directly from the new expression: the locale is responsible for invoking the matching delete from its own destructor.

So yes, there will be delete

an object for you , but it is actually the instance std::locale

that does this, not the thread.

+4


source







All Articles