File-like option where the "file contents" comes from a string?

Andy Valencia dont at spam.me
Wed Nov 27 21:10:04 UTC 2024


On Wednesday, 27 November 2024 at 20:38:22 UTC, monkyyy wrote:
> On Wednesday, 27 November 2024 at 14:37:03 UTC, Andy Valencia 
> wrote:
>> With my OO programming goggles on, I can't help but notice 
>> that if Phobos had made File a class--or an interface--
>
> oo doesn't own polymorphism you could do 99% of the value with
>
> ```d
> struct dummyfile{
>   auto byLineCopy()=>//string.spiltter('\n')....
> }
>
> auto myfunc(F)(F file){
>   foreach(s;file.byLineCopy){
>     ...
>   }
> }

Yes, the page pointed to by Ali Çehreli up above shows this, thus 
my comment about how OO techniques avoid the "big hammer" of 
macro expansion (well, template expansion...).

Andy



More information about the Digitalmars-d-learn mailing list