From f90ff0e9f610c15f0045bcb00d49a0253a10366e Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 22 Aug 2012 16:12:54 +1000 Subject: [PATCH] Add a unique_ptr/ptr comparator object --- Makefile.am | 2 ++ types/comparator.hpp | 35 +++++++++++++++++++++++++++++++ types/comparator.ipp | 49 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 types/comparator.hpp create mode 100644 types/comparator.ipp diff --git a/Makefile.am b/Makefile.am index 5ef85581..b86f0816 100644 --- a/Makefile.am +++ b/Makefile.am @@ -117,6 +117,8 @@ UTIL_FILES = \ types.hpp \ types/bits.hpp \ types/casts.hpp \ + types/comparator.hpp\ + types/comparator.ipp\ types/string.cpp \ types/string.hpp \ types/traits.hpp \ diff --git a/types/comparator.hpp b/types/comparator.hpp new file mode 100644 index 00000000..160748a0 --- /dev/null +++ b/types/comparator.hpp @@ -0,0 +1,35 @@ +/* + * This file is part of libgim. + * + * libgim is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * libgim 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 libgim. If not, see . + * + * Copyright 2012 Danny Robson + */ + +#ifndef __UTIL_TYPES_COMPARATOR_HPP +#define __UTIL_TYPES_COMPARATOR_HPP + +#include + +namespace util { + template + struct pointer_comparator { + bool operator() (const std::unique_ptr &lhs, const std::unique_ptr &rhs); + bool operator() (const T *lhs, const std::unique_ptr &rhs); + bool operator() (const std::unique_ptr &lhs, const T *rhs); + }; +} + +#include "util/types/comparator.ipp" +#endif diff --git a/types/comparator.ipp b/types/comparator.ipp new file mode 100644 index 00000000..388a1f9e --- /dev/null +++ b/types/comparator.ipp @@ -0,0 +1,49 @@ +/* + * This file is part of libgim. + * + * libgim is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * libgim 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 libgim. If not, see . + * + * Copyright 2012 Danny Robson + */ + +#ifdef __UTIL_TYPES_COMPARATOR_IPP +#error "Double inclusion for util/types/comparator.ipp" +#endif + +#define __UTIL_TYPES_COMPARATOR_IPP + + +//----------------------------------------------------------------------------- +namespace util { + template + bool + pointer_comparator::operator() (const std::unique_ptr &lhs, + const std::unique_ptr &rhs) + { return lhs < rhs; } + + + template + bool + pointer_comparator::operator() (const T *lhs, + const std::unique_ptr &rhs) + { return lhs < rhs.get (); } + + + template + bool + pointer_comparator::operator() (const std::unique_ptr &lhs, + const T *rhs) + { return lhs.get () < rhs; } +} +