Index: integre/ChangeLog
from Niels Van Vliet <niels(a)lrde.epita.fr>
* integre/ntg/core/pred_succ.hh: Add default_less.
* integre/ntg/color/color.hh: Add default_less specialization.
Index: integre/ntg/color/color.hh
--- integre/ntg/color/color.hh Thu, 22 Jan 2004 21:46:17 +0100 palma_g
(oln/t/20_color.hh 1.6 640)
+++ integre/ntg/color/color.hh Tue, 30 Mar 2004 12:38:04 +0200 van-vl_n
(oln/t/20_color.hh 1.6 640)
@@ -1,4 +1,4 @@
-// Copyright (C) 2001, 2002, 2003 EPITA Research and Development
Laboratory
+// Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development
Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -35,6 +35,7 @@
# include <ntg/basics.hh>
# include <ntg/int.hh>
# include <ntg/vect/vec.hh>
+# include <ntg/core/pred_succ.hh>
# include <mlc/cmp.hh>
@@ -268,6 +269,38 @@
}
};
+
+ template <typename T> struct default_less;
+
+ /*! The specialized version of default_less for colors.
+ **
+ ** \warning This class is only provided to build classes
+ ** that need a less class, it does not correspond to
+ ** the reality. \n
+ ** Example of a std::set of RGB colors:
+ ** \verbatim
+ ** std::set<ntg:rgb_8,
+ ** ntg::internal::default_less<ntg::rgb8> > s;
+ ** s.insert(ntg::rgb_8(10, 16, 64));
+ ** \endverbatim
+ */
+ template <unsigned ncomps,
+ unsigned qbits,
+ template <unsigned> class color_system>
+ struct default_less< ntg::color<ncomps, qbits, color_system> >
+ {
+ typedef ntg::color<ncomps, qbits, color_system> arg_type;
+ bool operator()(const arg_type& l,
+ const arg_type& r) const
+ {
+ for (unsigned i = 0; i < ntg_nb_comp(arg_type); ++i)
+ if (l[i] < r[i])
+ return true;
+ else if (l[i] > r[i])
+ return false;
+ return false;
+ }
+ };
} // end of internal.
} // end of ntg.
Index: integre/ntg/core/pred_succ.hh
--- integre/ntg/core/pred_succ.hh Fri, 19 Mar 2004 11:53:50 +0100
van-vl_n (oln/k/8_pred_succ. 1.1 644)
+++ integre/ntg/core/pred_succ.hh Tue, 30 Mar 2004 12:24:42 +0200
van-vl_n (oln/k/8_pred_succ. 1.1 644)
@@ -28,8 +28,10 @@
#ifndef NTG_CORE_PRED_SUCC_HH
# define NTG_CORE_PRED_SUCC_HH
-#include <ntg/all.hh>
+
#include <mlc/is_a.hh>
+#include <ntg/real/int_u.hh>
+#include <ntg/core/macros.hh>
namespace ntg {
@@ -70,6 +72,24 @@
{
return T(internal::with_arith<T>::ret(t) - 1);
}
+
+ namespace internal {
+ /*! Default less.
+ **
+ ** Specialization of this class provides a less functor even for
+ ** types that do not support the operator "<".
+ */
+ template <typename T>
+ struct default_less
+ {
+ typedef T arg_type;
+ bool operator()(const T& l,
+ const T& r) const
+ {
+ return l < r;
+ }
+ };
+ }
}
#endif