实例化redBlackTree模板时出错 [英] error instantiating redBlackTree template

查看:120
本文介绍了实例化redBlackTree模板时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用char实例化RedBlackTree容器时遇到了麻烦,但是它可以与ints一起使用:

import std.stdio;
import std.container;

void main()
{
        auto r1 = redBlackTree!(int)();   // works
        auto r2 = redBlackTree!(char)();  // error instantiating
}

我正在使用DMD32 D编译器v2.060.

有什么想法吗?谢谢.

解决方案

,您需要使用可比较的类型(即可以使用<运算符或提供自己的比较器作为第二个模板参数

char(和wchar)仅用于数组中,因为一个char不一定与unicode(UTF8版)中的实际字母相关,这还有其他陷阱会触发D中的新编码器 另一方面,

dchar总是与一个字母相对应,因此与另一个字母类似,

D中的经验法则始终使用dchar,除非它用于字符串类型(甚至考虑使用dstring)

I'm having trouble instantiating a RedBlackTree container with chars, but it works with ints:

import std.stdio;
import std.container;

void main()
{
        auto r1 = redBlackTree!(int)();   // works
        auto r2 = redBlackTree!(char)();  // error instantiating
}

I'm using DMD32 D Compiler v2.060.

Any thoughts? Thanks.

解决方案

you need to use a type that is comparable (i.e. can use the < operator or provide your own comparator as the second template parameter

char (and wchar) is only useful for use in arrays due to one char not necessarily relating to an actual letter in unicode (UTF8 edition) this has other gotcha that will trip up new coders in D

dchar on the other hand will always correspond to a letter and as such is comparable to another letter,

rule of thumb in D always use dchar unless it's for a string type (and even then consider using dstring)

这篇关于实例化redBlackTree模板时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆