aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-03-10 18:14:45 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-03-10 18:14:45 +0000
commit586f2efe31338d3734fd7359e346eaf6b2514f0e (patch)
tree18a282afd5657b611150e8ae5792bb2818013952
parent4240c68350ce8a4cefc70e1803d2cb59b9c039bc (diff)
downloadpaludis-586f2efe31338d3734fd7359e346eaf6b2514f0e.tar.gz
paludis-586f2efe31338d3734fd7359e346eaf6b2514f0e.tar.xz
Better iterator utilities
-rw-r--r--configure.ac29
-rw-r--r--paludis/util/iterator.hh39
-rw-r--r--paludis/util/iterator_TEST.cc18
-rw-r--r--tr1/Makefile.am35
-rw-r--r--tr1/tr1_type_traits.hh37
5 files changed, 139 insertions, 19 deletions
diff --git a/configure.ac b/configure.ac
index aff4ca4..ee86f55 100644
--- a/configure.ac
+++ b/configure.ac
@@ -230,6 +230,35 @@ int main(int, char *[])
AM_CONDITIONAL([NEED_POINTER_WRAPPERS], test x$need_pointer_wrappers = "xyes")
dnl }}}
+dnl {{{ tr1 type traits
+need_type_traits_wrappers=no
+AC_MSG_CHECKING([for std::tr1::remove_pointer<>])
+AC_COMPILE_IFELSE([
+#include <tr1/type_traits>
+int main(int, char *[])
+{
+ std::tr1::remove_pointer<int *>::type x(10);
+ return x;
+}
+],
+ [AC_MSG_RESULT([yes])],
+ [AC_MSG_RESULT([no])
+ AC_MSG_CHECKING([for boost::remove_pointer<>])
+ AC_COMPILE_IFELSE([
+#include <boost/type_traits.hpp>
+int main(int, char *[])
+{
+ boost::remove_pointer<int *>::type x(10);
+ return x;
+}
+],
+ [AC_MSG_RESULT([yes])
+ need_type_traits_wrappers=yes],
+ [AC_MSG_RESULT([no])
+ AC_MSG_ERROR([Your compiler doesn't support tr1 and boost is not installed])])])
+AM_CONDITIONAL([NEED_TYPE_TRAITS_WRAPPERS], test x$need_type_traits_wrappers = "xyes")
+dnl }}}
+
need_xml_check=
need_pcrepp_check=
diff --git a/paludis/util/iterator.hh b/paludis/util/iterator.hh
index bba7492..db70c5b 100644
--- a/paludis/util/iterator.hh
+++ b/paludis/util/iterator.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
*
* 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
@@ -20,11 +20,14 @@
#ifndef PALUDIS_GUARD_PALUDIS_INDIRECT_ITERATOR_HH
#define PALUDIS_GUARD_PALUDIS_INDIRECT_ITERATOR_HH 1
-#include <iterator>
-#include <functional>
#include <paludis/util/comparison_policy.hh>
#include <paludis/util/instantiation_policy.hh>
+#include <iterator>
+#include <functional>
+#include <tr1/type_traits>
+#include <tr1/memory>
+
/** \file
* Declarations for various iterator helpers.
*
@@ -57,7 +60,31 @@ namespace paludis
return --result;
}
- template <typename Iter_, typename Value_>
+ /**
+ * Like std::tr1::remove_pointer, for std::tr1::shared_ptr.
+ *
+ * \ingroup grpiterators
+ */
+ template <typename T_>
+ struct RemoveSharedPointer
+ {
+ typedef T_ Type;
+ };
+
+ template <typename T_>
+ struct RemoveSharedPointer<std::tr1::shared_ptr<T_> >
+ {
+ typedef T_ Type;
+ };
+
+ template <typename T_>
+ struct RemoveSharedPointer<const std::tr1::shared_ptr<T_> >
+ {
+ typedef T_ Type;
+ };
+
+ template <typename Iter_, typename Value_ =
+ typename RemoveSharedPointer<typename std::tr1::remove_pointer<typename Iter_::value_type>::type>::Type>
class IndirectIterator;
namespace
@@ -389,7 +416,7 @@ namespace paludis
*/
template <typename A_, typename B_>
struct SelectFirst :
- std::unary_function<A_, std::pair<A_, B_> >
+ std::unary_function<std::pair<A_, B_>, A_ >
{
/// Carry out the selection.
A_ operator() (const std::pair<A_, B_> & p) const
@@ -405,7 +432,7 @@ namespace paludis
*/
template <typename A_, typename B_>
struct SelectSecond :
- std::unary_function<B_, std::pair<A_, B_> >
+ std::unary_function<std::pair<A_, B_>, B_ >
{
/// Carry out the selection.
B_ operator() (const std::pair<A_, B_> & p) const
diff --git a/paludis/util/iterator_TEST.cc b/paludis/util/iterator_TEST.cc
index 6003343..709e3dd 100644
--- a/paludis/util/iterator_TEST.cc
+++ b/paludis/util/iterator_TEST.cc
@@ -24,6 +24,7 @@
#include <test/test_runner.hh>
#include <vector>
#include <set>
+#include <map>
#include <tr1/memory>
using namespace test;
@@ -98,7 +99,7 @@ namespace test_cases
std::list<std::tr1::shared_ptr<int> > v;
v.push_back(std::tr1::shared_ptr<int>(new int(5)));
v.push_back(std::tr1::shared_ptr<int>(new int(10)));
- IndirectIterator<std::list<std::tr1::shared_ptr<int> >::iterator, int> vi(v.begin()), vi_end(v.end());
+ IndirectIterator<std::list<std::tr1::shared_ptr<int> >::iterator> vi(v.begin()), vi_end(v.end());
TEST_CHECK(vi != vi_end);
TEST_CHECK_EQUAL(*vi, 5);
TEST_CHECK(++vi != vi_end);
@@ -258,12 +259,13 @@ namespace test_cases
} test_iterator_previous;
}
-#ifndef DOXYGEN
-int f(const int & v)
+namespace
{
- return -v;
+ int f(const int & v)
+ {
+ return -v;
+ }
}
-#endif
namespace test_cases
{
@@ -299,9 +301,9 @@ namespace test_cases
void run()
{
- std::pair<int,int> p(1,2);
- SelectFirst<int,int> f;
- SelectSecond<int,int> s;
+ std::pair<int, int> p(1,2);
+ SelectFirst<int, int> f;
+ SelectSecond<int, int> s;
TEST_CHECK(f(p) == 1);
TEST_CHECK(s(p) == 2);
diff --git a/tr1/Makefile.am b/tr1/Makefile.am
index 7068052..83e5a19 100644
--- a/tr1/Makefile.am
+++ b/tr1/Makefile.am
@@ -1,4 +1,4 @@
-CLEANFILES = *~ gmon.out *.gcov *.gcno *.gcda memory
+CLEANFILES = *~ gmon.out *.gcov *.gcno *.gcda memory type_traits
MAINTAINERCLEANFILES = Makefile.in
AM_CXXFLAGS = -I$(top_srcdir) @PALUDIS_CXXFLAGS@ @PALUDIS_CXXFLAGS_VISIBILITY@
@@ -10,11 +10,23 @@ DEFS= \
paludis_compat_tr1dir = $(includedir)/paludis/compat/tr1
-paludis_compat_tr1_HEADERS = tr1_memory.hh
+paludis_compat_tr1_HEADERS = tr1_memory.hh tr1_type_traits.hh
if NEED_POINTER_WRAPPERS
-
+if NEED_TYPE_TRAITS_WRAPPERS
+nodist_paludis_compat_tr1_HEADERS = memory type_traits
+else
nodist_paludis_compat_tr1_HEADERS = memory
+endif
+else
+if NEED_TYPE_TRAITS_WRAPPERS
+nodist_paludis_compat_tr1_HEADERS = type_traits
+else
+nodist_paludis_compat_tr1_HEADERS =
+endif
+endif
+
+if NEED_POINTER_WRAPPERS
memory : tr1_memory.hh
cp $(srcdir)/tr1_memory.hh $@
@@ -26,8 +38,21 @@ memory :
endif
-EXTRA_DIST = tr1_memory.hh
-BUILT_SOURCES = memory
+if NEED_TYPE_TRAITS_WRAPPERS
+
+type_traits : tr1_type_traits.hh
+ cp $(srcdir)/tr1_type_traits.hh $@
+
+else
+
+type_traits :
+ rm -f $@ || true
+
+endif
+
+
+EXTRA_DIST = tr1_memory.hh tr1_type_traits.hh
+BUILT_SOURCES = memory type_traits
SUBDIRS = .
built-sources : $(BUILT_SOURCES)
diff --git a/tr1/tr1_type_traits.hh b/tr1/tr1_type_traits.hh
new file mode 100644
index 0000000..3c07636
--- /dev/null
+++ b/tr1/tr1_type_traits.hh
@@ -0,0 +1,37 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+ *
+ * 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_TR1_TR1_TYPE_TRAITS_HH
+#define PALUDIS_GUARD_TR1_TR1_TYPE_TRAITS_HH 1
+
+/*
+ * Used if we have boost but not std::tr1::type_traits<>.
+ */
+
+#include <boost/type_traits.hpp>
+
+namespace std
+{
+ namespace tr1
+ {
+ using boost::remove_pointer;
+ }
+}
+
+#endif