|
Boost : |
Subject: Re: [boost] [filesystem] home_directory_path
From: Christian Holmquist (c.holmquist_at_[hidden])
Date: 2010-10-19 19:26:14
>
>>
>
> I have no preference for either enum based or multiple function based
> solution, but I am curious to what the benifit of an enum based solution is.
>
> --
>
I prefer to use enumerations when the interface allows, cause one can add
string operators to them for debugging purposes and keep them around more
easily in user-defined structs. Exceptions thrown from get_os_path() might
include the discriminator, making things a little easier at the catch site..
namespace example
{
struct user_file_path
{
filesystem::os_path_t root;
filesystem::path file_path;
filesystem::path get() { return filesystem::get_os_path(root) / file_path;
}
};
void foo()
{
user_file_path p = {..., ....};
try
{
p.get():
}
catch(const bad_os_path& p)
{
clog << "failed to get os path " << p.os_path();
}
}
}
Christian
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk