* mln/metal/is_a.hh: Move yes_/no_ structures...
* mln/metal/bool.hh: ... here.
* tests/metal/Makefile.am: Add new target.
* mln/metal/is_from_to_convertible.hh,
* tests/metal/is_from_to_convertible.cc: New.
---
milena/ChangeLog | 12 ++++
milena/mln/metal/bool.hh | 12 +++-
milena/mln/metal/is_a.hh | 7 +--
.../mln/metal/{is.hh => is_from_to_convertible.hh} | 68 +++++++++++---------
milena/tests/metal/Makefile.am | 5 +-
.../is_from_to_convertible.cc} | 19 ++---
6 files changed, 73 insertions(+), 50 deletions(-)
copy milena/mln/metal/{is.hh => is_from_to_convertible.hh} (51%)
copy milena/tests/{fun/v2v/qt_rgb_to_int_u.cc => metal/is_from_to_convertible.cc}
(76%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index c23b608..26c9973 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,15 @@
+2013-03-22 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Introduce mln_is_from_to_convertible.
+
+ * mln/metal/is_a.hh: Move yes_/no_ structures...
+ * mln/metal/bool.hh: ... here.
+
+ * tests/metal/Makefile.am: Add new target.
+
+ * mln/metal/is_from_to_convertible.hh,
+ * tests/metal/is_from_to_convertible.cc: New.
+
2013-03-21 Guillaume Lazzara <z(a)lrde.epita.fr>
* tests/unit_test/unit-tests.mk: Regen.
diff --git a/milena/mln/metal/bool.hh b/milena/mln/metal/bool.hh
index 4b6ff59..c32acdb 100644
--- a/milena/mln/metal/bool.hh
+++ b/milena/mln/metal/bool.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008, 2009, 2012 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009, 2012, 2013 EPITA Research and
+// Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -50,6 +50,14 @@ namespace mln
// Fwd decl.
template <bool b> struct bool_;
+ namespace internal
+ {
+
+ typedef char yes_;
+ struct no_ { char dummy[2]; };
+
+ }
+
/*!
\internal
diff --git a/milena/mln/metal/is_a.hh b/milena/mln/metal/is_a.hh
index 7a0c803..3f7b28f 100644
--- a/milena/mln/metal/is_a.hh
+++ b/milena/mln/metal/is_a.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008, 2009, 2012 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009, 2012, 2013 EPITA Research and
+// Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -62,9 +62,6 @@ namespace mln
namespace internal
{
- typedef char yes_;
- struct no_ { char dummy[2]; };
-
template <typename T>
struct make_
{
diff --git a/milena/mln/metal/is.hh b/milena/mln/metal/is_from_to_convertible.hh
similarity index 51%
copy from milena/mln/metal/is.hh
copy to milena/mln/metal/is_from_to_convertible.hh
index f4f2c10..02eb294 100644
--- a/milena/mln/metal/is.hh
+++ b/milena/mln/metal/is_from_to_convertible.hh
@@ -1,5 +1,4 @@
-// Copyright (C) 2007, 2008, 2009, 2012 EPITA Research and Development
-// Laboratory (LRDE)
+// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -24,23 +23,32 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_METAL_IS_HH
-# define MLN_METAL_IS_HH
+#ifndef MLN_METAL_IS_FROM_TO_CONVERTIBLE_HH
+# define MLN_METAL_IS_FROM_TO_CONVERTIBLE_HH
/// \file
///
-/// \brief Definition of a type that means "is".
+/// \brief Definition of a type that checks if a from_to_() conversion
+/// routine exists.
-# include <mln/metal/is_a.hh>
+/// FIXME: Enable this include if the compiler support c++-11
+# include <type_traits>
+# include <mln/metal/bool.hh>
-
-# define mlc_is(T, U) mln::metal::is< T, U >
+# define mlc_is_from_to_convertible(T, U) mln::metal::is_from_to_convertible< T, U
>
namespace mln
{
+ // Forward declarations.
+ namespace value {
+ template <unsigned n> struct int_u;
+ template <unsigned n> struct int_s;
+ }
+
+
namespace metal
{
@@ -48,10 +56,22 @@ namespace mln
{
template <typename T, typename U>
- struct helper_is_
+ struct helper_is_from_to_convertible_
{
- static yes_ selector(U*const);
static no_ selector(...);
+
+
+ /// FIXME: Enable this implementation if the compiler supports it.
+
+ // template <typename V>
+ // static yes_ selector(V, typeof(from_to_(*(V*)0, static_cast<U&>(*(U*)0)))*
= 0);
+
+ /// FIXME: Enable this implementation with latest compilers supporting c++-11.
+
+ template <typename V, typename C = decltype(from_to_(V(),
std::declval<U&>()))>
+ static yes_ selector(V);
+
+ static const bool value = sizeof(selector(T())) == sizeof(char);
};
} // end of namespace mln::metal::internal
@@ -60,35 +80,23 @@ namespace mln
/*!
\internal
- \brief "is" check.
- Check whether T inherits from U.
+ \brief Checks if a from_to_() conversion routine exists.
+
+ \warning This structure may use C++-11 features if available or
+ typeof keyword which is a specific feature of g++. Be sure that
+ your compiler supports them.
*/
template <typename T, typename U>
- struct is : bool_<( sizeof(internal::helper_is_<T,
U>::selector(internal::make_<T>::ptr()))
- ==
- sizeof(internal::yes_) )>
+ struct is_from_to_convertible :
bool_<internal::helper_is_from_to_convertible_<T,U>::value>
{
};
- template <typename T, typename U>
- struct is< const T, const U > : is<T, U>::eval
- {};
-
- template <typename T, typename U>
- struct is< T*, U* > : is<T, U>::eval
- {};
- template <typename T, typename U>
- struct is< T&, U& > : is<T, U>::eval
- {};
+ } // end of namespace mln::metal
- template <typename T, typename U>
- struct is< T**, U** > : false_
- {};
- } // end of namespace mln::metal
} // end of namespace mln
-#endif // ! MLN_METAL_IS_HH
+#endif // ! MLN_METAL_IS_FROM_TO_CONVERTIBLE_HH
diff --git a/milena/tests/metal/Makefile.am b/milena/tests/metal/Makefile.am
index cf4be2d..288c5a6 100644
--- a/milena/tests/metal/Makefile.am
+++ b/milena/tests/metal/Makefile.am
@@ -1,5 +1,5 @@
-# Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
-# Laboratory (LRDE)
+# Copyright (C) 2007, 2008, 2009, 2010, 2013 EPITA Research and
+# Development Laboratory (LRDE)
#
# This file is part of Olena.
#
@@ -22,6 +22,7 @@ SUBDIRS = make math
check_PROGRAMS = \
converts_to \
is \
+ is_from_to_convertible \
unconst
diff --git a/milena/tests/fun/v2v/qt_rgb_to_int_u.cc
b/milena/tests/metal/is_from_to_convertible.cc
similarity index 76%
copy from milena/tests/fun/v2v/qt_rgb_to_int_u.cc
copy to milena/tests/metal/is_from_to_convertible.cc
index 5b55d49..2c289ec 100644
--- a/milena/tests/fun/v2v/qt_rgb_to_int_u.cc
+++ b/milena/tests/metal/is_from_to_convertible.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2013 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,22 +23,19 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#include <mln/core/image/image2d.hh>
-
-#include <mln/fun/v2v/qt_rgb_to_int_u.hh>
-#include <mln/value/qt/rgb32.hh>
#include <mln/value/int_u8.hh>
+#include <mln/value/rgb8.hh>
+#include <mln/metal/is_from_to_convertible.hh>
int main()
{
using namespace mln;
- fun::v2v::qt_rgb_to_int_u<8> f;
-
- value::qt::rgb32 vcolor(100, 200, 30);
-
- value::int_u8 vgl = f(vcolor);
+ bool b = metal::converts_to<value::rgb8, int>::value;
+ mln_assertion(! b);
- mln_assertion(vgl == 110);
+ b = metal::converts_to<value::int_u8, value::rgb8>::value;
+ std::cout << metal::converts_to<value::int_u8, value::rgb8>::name()
<< std::endl;
+ mln_assertion(b);
}
--
1.7.2.5