www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to use UFCS and std.algorithm.sort?

reply "Andre" <andre s-e-a-p.de> writes:
Hi,

with the new beta I get the warning I should use 
std.algorithm.sort instead the .sort property. I thought the 
std.algorithm.sort method is used in this example?

void main()
{	
	import std.algorithm: sort, uniq, map;
	import std.array: array;
	
	string[] arr = ["A","B","B","C"];

	string[] result = arr
		.map!(n => n) // minified
		.array
		.sort
		.uniq
		.array;
}

I want to use the sort template with the default less "a < b" 
without specifying !("a < b")

Kind regards
André
Mar 10 2015
next sibling parent "Tobias Pankrath" <tobias pankrath.net> writes:
 		.array
 		.sort
buildin arrays have a .sort-property that is called.
Mar 10 2015
prev sibling parent reply Jonathan M Davis via Digitalmars-d-learn writes:
On Tuesday, March 10, 2015 07:24:52 Andre via Digitalmars-d-learn wrote:
 Hi,

 with the new beta I get the warning I should use
 std.algorithm.sort instead the .sort property. I thought the
 std.algorithm.sort method is used in this example?

 void main()
 {
   import std.algorithm: sort, uniq, map;
   import std.array: array;

   string[] arr = ["A","B","B","C"];

   string[] result = arr
       .map!(n => n) // minified
       .array
       .sort
       .uniq
       .array;
 }

 I want to use the sort template with the default less "a < b"
 without specifying !("a < b")
.sort on an array is going to use the built-in sort property. You need to use parens if you want to use the function in std.algorithm with an array and UFCS, e.g. arr.sort(); - Jonathan M Davis
Mar 10 2015
next sibling parent "Andre" <andre s-e-a-p.de> writes:
Thanks a lot!

Kind regards
André

On Tuesday, 10 March 2015 at 08:40:28 UTC, Jonathan M Davis wrote:
 On Tuesday, March 10, 2015 07:24:52 Andre via 
 Digitalmars-d-learn wrote:
 Hi,

 with the new beta I get the warning I should use
 std.algorithm.sort instead the .sort property. I thought the
 std.algorithm.sort method is used in this example?

 void main()
 {
   import std.algorithm: sort, uniq, map;
   import std.array: array;

   string[] arr = ["A","B","B","C"];

   string[] result = arr
       .map!(n => n) // minified
       .array
       .sort
       .uniq
       .array;
 }

 I want to use the sort template with the default less "a < b"
 without specifying !("a < b")
.sort on an array is going to use the built-in sort property. You need to use parens if you want to use the function in std.algorithm with an array and UFCS, e.g. arr.sort(); - Jonathan M Davis
Mar 10 2015
prev sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 03/10/2015 01:40 AM, Jonathan M Davis via Digitalmars-d-learn wrote:

 .sort on an array is going to use the built-in sort property. You need to
 use parens if you want to use the function in std.algorithm with an array
 and UFCS, e.g.

 arr.sort();
Didn't know that. Nice! Another option is to use renamed imports[1] but it is hard to come up with an acceptable name other than sort: import std.algorithm: algSort = sort, uniq, map; // <-- HERE // ... string[] result = arr .map!(n => n) // minified .array .algSort // <-- HERE .uniq .array; Ali [1] http://dlang.org/module.html
Mar 10 2015