我 m越多,越少越野,这也许是一个 st问题,但我没有设法找到任何简单的解决办法。
在C++中,我有这样的一类:
template<class T> class Node {...}
而我需要的是T,至少要有=和提;以及界定操作者。 是否有任何<>简单明了<>方法? Java就是这样:
public class Node<T extends Comparable> { ... }
感谢你们的帮助!
我 m越多,越少越野,这也许是一个 st问题,但我没有设法找到任何简单的解决办法。
在C++中,我有这样的一类:
template<class T> class Node {...}
而我需要的是T,至少要有=和提;以及界定操作者。 是否有任何<>简单明了<>方法? Java就是这样:
public class Node<T extends Comparable> { ... }
感谢你们的帮助!
C++模板是duck-typed,因此没有必要进行接口或限制,汇编者如果存在,将使用比较操作者,并产生错误。
另见,详见。
如果你想避免加密错误(因为你经常在模版瞬时树中发生缺乏可比性的情况),那么,只要使用,就能够做到:
如果您有C++98或C++03汇编者,则推动:可使用:。
如果您有C++11汇编者,则编组如下:
尤其是,在“增强力”的理论中,研究“增强模范类专业”:可推广。
http://www.boost.org/doc/libs/release/libs/type_traits/doc/html/index.html
对您的案件特别感兴趣:
http://www.boost.org/doc/libs/release/libs/type_traits/doc/html/boost_typetraits/vis:/has_ Equal_to.html”rel=“nofollow” http://www.boost.org/doc/libs/release/libs/type_traits/doc/html/boost_types/vis:/has_ Equal_to.html
But see also has_greater, has_greater_equal, has_less, has_less_equal, etc. // I m actually somewhat surprised that there isn t a straightforward is_equality_comparable type-trait.
// EDIT: it appears I ve found it, it s ::boost::is_equality_comparable::value in the Concept Traits Library: http://neoscientists.org/~tschwinger/boostdev/concept_traits/libs/concept_traits/doc/
另一种解决办法是使用“夜总会”概念查询图书馆,特别是适用“平等委员会”概念:
rel=“nofollow”http://www.boost.org/doc/libs/release/libs/concept_check/using_concept_check.htm
还有另一种选择: Boost.Generic -- https://svn.boost.org/trac/boost/wiki/Libraries UnderConstruction#Boost.Generic
Yet another alternative: http://code.google.com/p/origin/source/browse/trunk/core/tests/concepts/equality_comparable.cpp
目前在C++20概念图书馆是可能的。
class Node<T> requires Compare<T> {...}
虽然如果这一概念不满意,这仍会犯错误,但更容易理解造成错误的原因。 您可以在其周围写一个包裹,以预防错误。
如果贵模板类别使用你提到的操作人员,如果模板类型论点没有支持这些操作者,汇编者就会发现错误。
I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...
I have been searching for sample code creating iterator for my own container, but I haven t really found a good example. I know this been asked before (Creating my own Iterators) but didn t see any ...
Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...
I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?
Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...
Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?