Jump to page: 1 210  
Page
Thread overview
Feature request: Path append operators for strings
Jul 02, 2013
TommiT
Jul 02, 2013
Simen Kjaeraas
Jul 02, 2013
Jonathan M Davis
Jul 02, 2013
TommiT
Jul 02, 2013
monarch_dodra
Jul 02, 2013
TommiT
Jul 02, 2013
Walter Bright
Jul 02, 2013
Araq
Jul 02, 2013
TommiT
Jul 02, 2013
TommiT
Jul 02, 2013
Jonathan M Davis
Jul 02, 2013
John Colvin
Jul 03, 2013
Wyatt
Jul 03, 2013
TommiT
Jul 03, 2013
Wyatt
Jul 03, 2013
monarch_dodra
Jul 03, 2013
TommiT
Jul 03, 2013
TommiT
Jul 03, 2013
John Colvin
Jul 03, 2013
w0rp
Jul 03, 2013
H. S. Teoh
Jul 03, 2013
Martin Primer
Jul 08, 2013
Wyatt
Jul 02, 2013
monarch_dodra
Jul 02, 2013
Walter Bright
Jul 05, 2013
TommiT
Jul 05, 2013
Paulo Pinto
Jul 05, 2013
TommiT
Jul 05, 2013
H. S. Teoh
Jul 05, 2013
Walter Bright
Jul 05, 2013
H. S. Teoh
Jul 05, 2013
Wyatt
Jul 05, 2013
Peter Alexander
Jul 05, 2013
Jonathan M Davis
Jul 05, 2013
Namespace
Jul 05, 2013
Timon Gehr
Jul 05, 2013
Namespace
Jul 05, 2013
Jonathan M Davis
Jul 05, 2013
Timon Gehr
Jul 05, 2013
Timon Gehr
Jul 05, 2013
Jonathan M Davis
Jul 06, 2013
Walter Bright
Jul 05, 2013
Namespace
Jul 05, 2013
Jonathan M Davis
Jul 06, 2013
monarch_dodra
Jul 05, 2013
H. S. Teoh
Jul 05, 2013
John Colvin
Jul 06, 2013
Walter Bright
Jul 07, 2013
TommiT
Jul 07, 2013
Walter Bright
Jul 07, 2013
Walter Bright
Jul 07, 2013
Walter Bright
Jul 07, 2013
Walter Bright
Jul 08, 2013
H. S. Teoh
Jul 08, 2013
Walter Bright
Jul 08, 2013
Timothee Cour
Jul 08, 2013
Walter Bright
Jul 08, 2013
Tommi
Jul 08, 2013
John Colvin
Jul 08, 2013
Tommi
Jul 08, 2013
Walter Bright
Jul 08, 2013
Dicebot
Jul 08, 2013
Tommi
Jul 08, 2013
John Colvin
Jul 08, 2013
Dicebot
Jul 08, 2013
Dicebot
Jul 08, 2013
H. S. Teoh
Jul 08, 2013
Dicebot
Jul 08, 2013
deadalnix
Jul 08, 2013
Walter Bright
Jul 08, 2013
Dicebot
Jul 08, 2013
Walter Bright
Jul 09, 2013
Tommi
Jul 09, 2013
Tommi
Jul 09, 2013
deadalnix
Jul 09, 2013
Dicebot
Jul 09, 2013
John Colvin
Jul 09, 2013
deadalnix
Jul 08, 2013
Walter Bright
Jul 08, 2013
bearophile
Jul 07, 2013
John Colvin
Jul 07, 2013
Walter Bright
Jul 07, 2013
TommiT
Jul 07, 2013
John Colvin
Jul 07, 2013
Walter Bright
Jul 07, 2013
John Colvin
Jul 07, 2013
Jonathan M Davis
Jul 07, 2013
Adam D. Ruppe
Jul 07, 2013
Walter Bright
Jul 02, 2013
Artur Skawina
Jul 03, 2013
TommiT
July 02, 2013
How would you feel about adding the '/' binary operator and the '/=' assignment operator for strings, wstrings and dstrings? The operators would behave the same way as they do with boost::filesystem::path objects:

http://www.boost.org/doc/libs/1_54_0/libs/filesystem/doc/reference.html#path-appends

In short (and omitting some details) code such as:

string s = "C:\\Users" / "John";

...would be the same as:

string s = "C:\\Users" ~ std.path.dirSeparator ~ "John";
July 02, 2013
On 2013-07-02, 21:46, TommiT wrote:

> How would you feel about adding the '/' binary operator and the '/=' assignment operator for strings, wstrings and dstrings? The operators would behave the same way as they do with boost::filesystem::path objects:
>
> http://www.boost.org/doc/libs/1_54_0/libs/filesystem/doc/reference.html#path-appends
>
> In short (and omitting some details) code such as:
>
> string s = "C:\\Users" / "John";
>
> ...would be the same as:
>
> string s = "C:\\Users" ~ std.path.dirSeparator ~ "John";

This would be much better done with a library type:

auto s = Path("C:\\Users") / "John";

-- 
Simen
July 02, 2013
On Tuesday, July 02, 2013 21:46:26 TommiT wrote:
> How would you feel about adding the '/' binary operator and the '/=' assignment operator for strings, wstrings and dstrings? The operators would behave the same way as they do with boost::filesystem::path objects:
> 
> http://www.boost.org/doc/libs/1_54_0/libs/filesystem/doc/reference.html#path -appends
> 
> In short (and omitting some details) code such as:
> 
> string s = "C:\\Users" / "John";
> 
> ...would be the same as:
> 
> string s = "C:\\Users" ~ std.path.dirSeparator ~ "John";

That's what std.path.buildPath is for.

- Jonathan M Davis
July 02, 2013
On Tuesday, 2 July 2013 at 19:56:20 UTC, Jonathan M Davis wrote:
> On Tuesday, July 02, 2013 21:46:26 TommiT wrote:
>> How would you feel about adding the '/' binary operator and the
>> '/=' assignment operator for strings, wstrings and dstrings? The
>> operators would behave the same way as they do with
>> boost::filesystem::path objects:
>> 
>> http://www.boost.org/doc/libs/1_54_0/libs/filesystem/doc/reference.html#path
>> -appends
>> 
>> In short (and omitting some details) code such as:
>> 
>> string s = "C:\\Users" / "John";
>> 
>> ...would be the same as:
>> 
>> string s = "C:\\Users" ~ std.path.dirSeparator ~ "John";
>
> That's what std.path.buildPath is for.
>
> - Jonathan M Davis

Oh, I hadn't noticed that function. I don't know about its behaviour of dropping path components situated before a rooted path component. Throwing an Exception would seem like a better behaviour in that situation.
July 02, 2013
On Tuesday, 2 July 2013 at 19:46:34 UTC, TommiT wrote:
> How would you feel about adding the '/' binary operator and the '/=' assignment operator for strings, wstrings and dstrings? The operators would behave the same way as they do with boost::filesystem::path objects:

There is a *massive* difference here. boost::filesystem adds the
overload for *path* objects. It doesn't add a global operator for
any indiscriminate string.
July 02, 2013
On Tuesday, 2 July 2013 at 20:31:14 UTC, monarch_dodra wrote:
> On Tuesday, 2 July 2013 at 19:46:34 UTC, TommiT wrote:
>> How would you feel about adding the '/' binary operator and the '/=' assignment operator for strings, wstrings and dstrings? The operators would behave the same way as they do with boost::filesystem::path objects:
>
> There is a *massive* difference here. boost::filesystem adds the
> overload for *path* objects. It doesn't add a global operator for any indiscriminate string.

As far as I can tell, Phobos already uses strings or const(char)[] to represent paths all over the place. So, I figured, we can't add a separate Path type at this point because that train has passed. Although, I don't know if that design would have been a better anyway. Division operator for strings doesn't make any sense, and I doubt there will ever be some other meaning for '/' that would make more sense than "a directory separator" for strings in the context of programming.
July 02, 2013
On 7/2/2013 1:47 PM, TommiT wrote:
> Division operator for strings doesn't make any sense,

That's why overloading / to do something completely unrelated to division is anti-ethical to writing understandable code. The classic example of this is the overloading of << and >> for stream operations in C++.
July 02, 2013
On Tuesday, 2 July 2013 at 21:48:54 UTC, Walter Bright wrote:
> On 7/2/2013 1:47 PM, TommiT wrote:
>> Division operator for strings doesn't make any sense,
>
> That's why overloading / to do something completely unrelated to division is anti-ethical to writing understandable code. The classic example of this is the overloading of << and >> for stream operations in C++.

Before C came along, '<<' meant "much less" ...
July 02, 2013
On Tuesday, 2 July 2013 at 21:48:54 UTC, Walter Bright wrote:
> On 7/2/2013 1:47 PM, TommiT wrote:
>> Division operator for strings doesn't make any sense,
>
> That's why overloading / to do something completely unrelated to division is anti-ethical to writing understandable code. The classic example of this is the overloading of << and >> for stream operations in C++.

I've never thought of it like that. At some point I remember writing a vector type which overloaded its binary * operator to mean dot product (or cross product, I can't remember). So, you can overload an operator, but you can't overload the meaning of an operator.
July 02, 2013
On Tuesday, 2 July 2013 at 22:28:24 UTC, TommiT wrote:
>
> I've never thought of it like that. [..]

Boost Filesystem overloads the meaning of / to mean "append to path". Boost Exception overloads << to mean "add this info to this exception". Boost Serialization overloads << and >> to mean serialize and deserialize, and & to mean either one of those.

So no wonder I was under the impression that we're allowed to overload the meaning of operators.
« First   ‹ Prev
1 2 3 4 5 6 7 8 9 10