scoped chdir and similar patterns
Jacob Carlborg
doob at me.com
Wed Dec 4 23:36:44 PST 2013
On 2013-12-05 02:07, Timothee Cour wrote:
> A1.
>
> Is there a (clever?) way to achieve the following using a single
> function call?
>
> //does chdir
>
> void fun(){
> ...
> string dir0=getcwd; scope(exit) chdir(dir0); chdir(dir);
> ...
> }
>
> //desired:
> void fun(){
> ...
> chdir_scoped(dir);
> ...
> }
Delegates can be used as well:
chdir_scoped!({
chdir(dir);
});
void chdir_scoped (alias block) ()
{
string dir0=getcwd;
scope(exit) chdir(dir0);
block();
)
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list