www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12199] New: RedBlackTree problematic with non-string predicates

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12199

           Summary: RedBlackTree problematic with non-string predicates
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: xinok live.com


--- Comment #0 from Xinok <xinok live.com> 2014-02-18 16:53:48 PST ---
DMD 2.064.2
Windows 7 x64

I've encountered a number of issues which are difficult to sum up in a single
bug report. Simply put, any code which uses functional/non-string predicates
with RedBlackTree is highly likely to fail to compile.

The following line compiles fine:

auto a = redBlackTree!("a < b", int)(10, 20, 30, 40, 50);

But attempt to substitute "a < b" with an equivalent static function:

bool pred(int a, int b){ return a < b; }
void main()
{
    auto a = redBlackTree!(pred, int)(10, 20, 30, 40, 50);
}

Results in the compilation error:

std/container.d(6567): Error: pred (int a, int b) is not callable using
argument types ()

Things especially become problematic if you attempt to compile using unittests:

std/container.d(6567): Error: pred (int a, int b) is not callable using
argument types () 
std/container.d(5686): Error: function f38.pred (int a, int b) is not callable
using argument types () 
std/container.d(5960): Error: function f38.pred (int a, int b) is not callable
using argument types () 
std/container.d(6035): Error: function f38.pred (int a, int b) is not callable
using argument types () 
std/container.d(6081): Error: function f38.pred (int a, int b) is not callable
using argument types () 
std/container.d(6122): Error: function f38.pred (int a, int b) is not callable
using argument types () 
std/container.d(6243): Error: function f38.pred (int a, int b) is not callable
using argument types () 
std/container.d(6342): Error: function f38.pred (int a, int b) is not callable
using argument types () 
std/container.d(6575): Error: template instance
std.container.RedBlackTree!(int, pred) error instantiating /d665/f38.d(6):
instantiated from here: redBlackTree!(pred, int) /d665/f38.d(6): Error:
template instance std.container.redBlackTree!(pred, int) error instantiating

I think this line [1] shows how poorly written the unittests are. Attempting to
use any predicate other than "a < b" or "a > b" is likely to result in a
compiler or runtime error.

[1]
https://github.com/D-Programming-Language/phobos/blob/2.064/std/container.d#L5686

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 18 2014
parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=12199


Peter Alexander <peter.alexander.au gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peter.alexander.au gmail.co
                   |                            |m


--- Comment #1 from Peter Alexander <peter.alexander.au gmail.com> 2014-02-22
10:55:43 PST ---
Yes, the unit tests are quite horrible, but easy to fix.

Unfortunately, this is blocked by Issue 12225 because of this:

auto redBlackTree(bool allowDuplicates, E)(E[] elems...)
auto redBlackTree(alias less, E)(E[] elems...)

Unexpectedly, passing the predicate as a function matches the first overload,
and tries to call the predicate with no arguments to evaluate it as a bool,
instead of just matching to alias!

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 22 2014