aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-11-22 16:31:34 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-11-22 16:31:34 +0000
commitaf555e396371785e041229734dec335a6a9ee83f (patch)
tree903bbcb06285ed33c694d24ce225d6e09f78c1a0
parent9b99f1736116eb9825b3e547b12ef0891f3888f9 (diff)
downloadpaludis-af555e396371785e041229734dec335a6a9ee83f.tar.gz
paludis-af555e396371785e041229734dec335a6a9ee83f.tar.xz
simple_visitor_cast tweaks
Statically verify that a simple_visitor_cast can potentially work. Also work for non-const.
-rw-r--r--paludis/util/simple_visitor_cast-fwd.hh4
-rw-r--r--paludis/util/simple_visitor_cast.hh23
2 files changed, 21 insertions, 6 deletions
diff --git a/paludis/util/simple_visitor_cast-fwd.hh b/paludis/util/simple_visitor_cast-fwd.hh
index 3fcb4d7..7482c9b 100644
--- a/paludis/util/simple_visitor_cast-fwd.hh
+++ b/paludis/util/simple_visitor_cast-fwd.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008 Ciaran McCreesh
+ * Copyright (c) 2008, 2009 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -25,7 +25,7 @@
namespace paludis
{
template <typename To_, typename From_>
- To_ * simple_visitor_cast(const From_ &) PALUDIS_ATTRIBUTE((warn_unused_result));
+ To_ * simple_visitor_cast(From_ &) PALUDIS_ATTRIBUTE((warn_unused_result));
}
#endif
diff --git a/paludis/util/simple_visitor_cast.hh b/paludis/util/simple_visitor_cast.hh
index db74622..5337a0f 100644
--- a/paludis/util/simple_visitor_cast.hh
+++ b/paludis/util/simple_visitor_cast.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008 Ciaran McCreesh
+ * Copyright (c) 2008, 2009 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -29,20 +29,35 @@ namespace paludis
template <typename To_, typename From_>
struct SimpleVisitorCaster
{
- To_ * visit(const To_ & t)
+ To_ * visit(To_ & t)
{
return &t;
}
- To_ * visit(const From_ &)
+ To_ * visit(From_ &)
{
return 0;
}
};
+ template <typename To_, typename From_, bool ok_>
+ struct VerifySimpleVisitorCastType
+ {
+ };
+
+ template <typename To_, typename From_>
+ struct VerifySimpleVisitorCastType<To_, From_, true>
+ {
+ typedef int IsOK;
+ };
+
template <typename To_, typename From_>
- To_ * simple_visitor_cast(const From_ & from)
+ To_ * simple_visitor_cast(From_ & from)
{
+ /* verify that we are attempting to simple_visitor_cast something that
+ * could potentially be true */
+ typedef typename VerifySimpleVisitorCastType<To_, From_, std::tr1::is_base_of<From_, To_>::value>::IsOK TypeIsOK;
+
SimpleVisitorCaster<To_, From_> q;
return from.template accept_returning<To_ *>(q);
}