Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] {std.stdio} A range to manage both stream and file #9961

Open
dlangBugzillaToGithub opened this issue Mar 14, 2013 · 3 comments

Comments

@dlangBugzillaToGithub
Copy link

bioinfornatics (@bioinfornatics) reported this on 2013-03-14T03:45:19Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=9716

CC List

  • bearophile_hugs

Description

Dear,

When you need to manage various file format and trying to fit as a phobos File it appear below feature could be really interesting.

by example you have a parser you want to construct is from various file type you can grant some methods.

-----------------------------------------------------------


template isFileType(F)
{
    enum bool isFileType = is(typeof(
    {
        ubyte[] buf;
        F f = void;         // can define a FileType object
        if (f.eof) {}       // can test for end of file
        if (f.isOpen) {}    // can test for opened file
        f.name;             // can invoke name
        f.close();          // can invoke close
        r.write();          // can invoke write()
        r.rawWrite( "" );   // can invoke rawWrite()
        r.rawRead( buf );   // can invoke rawRead()
    }));
}


struct FileType( F ) if( isFileType( F ) )
{
    F _f;
    this( F file ){
        _f = file;
    }

    alias _f this;
}
@dlangBugzillaToGithub
Copy link
Author

bioinfornatics commented on 2013-03-17T17:29:05Z

By example we can do with it a range to manage both stream and file

http://dpaste.dzfl.pl/1f2bcf39

@dlangBugzillaToGithub
Copy link
Author

bearophile_hugs commented on 2013-03-17T17:42:28Z

I suggest you to give a more precise title to this issue.

@dlangBugzillaToGithub
Copy link
Author

bioinfornatics commented on 2013-03-18T01:05:51Z

English is not my first language so if you have a good one. You are welcome :-)

@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants