Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2005-04-23 09:44:51


On Sat, 23 Apr 2005 10:43:17 +0100, John Maddock wrote

> > lib. Not to mention that it is almost infinately flexible in terms of how
> > the
> > various types can be streamed. This code will be the standard i/o facet
> > in
> > the 1.33 release.
>
> Jeff, do you mind if I throw a wildcard in here?

Not at all...
 
> Why not drop facets altogether and use a stream format manipulator instead:
>
> std::cout << set_date_format("%Y-%b-%d") << mydate << std::endl;
>
> The format would be stored in the iostreams iword/pword (that's what
> they're for).

Sure, that would be easy enough to add now, but...

> You could still have a facet if you really wanted uses to change the
> *algorithm* used for io, but I guess what I'm trying to say is that:
>
> algorithms go in facets.
> configuration data goes in the iostream object itself.

I think there are some other considerations here with date-time. What if you
want to replace the short or long strings associated with a month output? Or
I want the 'days of the week' be 'day1', 'day2', instead of 'Sun', 'Mon', etc.
For these cases I think the strings need to get associated with a facet
instead of a fleeting i/o manipulator. So for example

//let's change all the short month names to have stars around them
const char* const month_short_names[]={"*jan*","*feb*","*mar*",
                                       "*apr*","*may*","*jun*",
                                       "*jul*","*aug*","*sep*",
                                       "*oct*","*nov*","*dec*"};

std::vector<std::basic_string<char> > short_month_names;

int
main()
{

  using namespace boost::gregorian;

  std::copy(&month_short_names[0],
            &month_short_names[12],
            std::back_inserter(short_month_names));

  date_facet* datefacet = new date_facet("%Y %b");
  datefacet->short_month_names(short_month_names);
  std::cout.imbue(std::locale(std::locale::classic(), datefacet));

  date d(2005,Apr, 20);
  std::cout << d << std::endl; //2005 *apr*

> Just my 2c worth,
>
> Hope this doesn't cloud things up to much!

No, not at all. I'm sure there will be some tweaking and optimizations of the
i/o concepts...

Jeff


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk