2007-05-04 21:30:54 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// (C) Copyright Olaf Krzikalla 2004-2006.
|
2013-07-28 22:10:37 +00:00
|
|
|
// (C) Copyright Ion Gaztanaga 2006-2013.
|
2007-05-04 21:30:54 +00:00
|
|
|
//
|
|
|
|
|
// Distributed under the Boost Software License, Version 1.0.
|
|
|
|
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
|
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
//
|
|
|
|
|
// See http://www.boost.org/libs/intrusive for documentation.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2007-09-26 17:39:06 +00:00
|
|
|
#ifndef BOOST_INTRUSIVE_DETAIL_ITESTVALUE_HPP
|
|
|
|
|
#define BOOST_INTRUSIVE_DETAIL_ITESTVALUE_HPP
|
2007-05-04 21:30:54 +00:00
|
|
|
|
|
|
|
|
#include <iostream>
|
2007-09-26 17:39:06 +00:00
|
|
|
#include <boost/intrusive/options.hpp>
|
2007-10-15 16:56:27 +00:00
|
|
|
#include <boost/functional/hash.hpp>
|
2007-05-04 21:30:54 +00:00
|
|
|
|
|
|
|
|
namespace boost{
|
|
|
|
|
namespace intrusive{
|
|
|
|
|
|
2008-12-13 13:49:31 +00:00
|
|
|
struct testvalue_filler
|
2007-11-18 10:44:56 +00:00
|
|
|
{
|
2008-12-13 13:49:31 +00:00
|
|
|
void *dummy_[3];
|
2007-11-18 10:44:56 +00:00
|
|
|
};
|
2007-09-26 17:39:06 +00:00
|
|
|
|
2008-12-13 13:49:31 +00:00
|
|
|
template<class Hooks, bool ConstantTimeSize>
|
2007-05-04 21:30:54 +00:00
|
|
|
struct testvalue
|
2008-12-13 13:49:31 +00:00
|
|
|
: testvalue_filler
|
|
|
|
|
, Hooks::base_hook_type
|
|
|
|
|
, Hooks::auto_base_hook_type
|
2007-05-04 21:30:54 +00:00
|
|
|
{
|
2008-12-13 13:49:31 +00:00
|
|
|
typename Hooks::member_hook_type node_;
|
|
|
|
|
typename Hooks::auto_member_hook_type auto_node_;
|
2007-05-04 21:30:54 +00:00
|
|
|
int value_;
|
|
|
|
|
|
2007-09-26 17:39:06 +00:00
|
|
|
static const bool constant_time_size = ConstantTimeSize;
|
2007-05-04 21:30:54 +00:00
|
|
|
|
|
|
|
|
testvalue()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
testvalue(int i)
|
|
|
|
|
: value_(i)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
testvalue (const testvalue& src)
|
|
|
|
|
: value_ (src.value_)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
// testvalue is used in std::vector and thus prev and next
|
|
|
|
|
// have to be handled appropriately when copied:
|
|
|
|
|
testvalue & operator= (const testvalue& src)
|
2008-12-13 13:49:31 +00:00
|
|
|
{
|
2014-02-08 18:27:24 +01:00
|
|
|
Hooks::base_hook_type::operator=(static_cast<const Hooks::base_hook_type&>(src));
|
|
|
|
|
Hooks::auto_base_hook_type::operator=(static_cast<const Hooks::auto_base_hook_type&>(src));
|
2008-12-13 13:49:31 +00:00
|
|
|
this->node_ = src.node_;
|
|
|
|
|
this->auto_node_ = src.auto_node_;
|
2007-05-04 21:30:54 +00:00
|
|
|
value_ = src.value_;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void swap_nodes(testvalue &other)
|
|
|
|
|
{
|
2014-02-08 18:27:24 +01:00
|
|
|
Hooks::base_hook_type::swap_nodes(static_cast<Hooks::base_hook_type&>(other));
|
|
|
|
|
Hooks::auto_base_hook_type::swap_nodes(static_cast<Hooks::auto_base_hook_type&>(other));
|
2008-12-13 13:49:31 +00:00
|
|
|
node_.swap_nodes(other.node_);
|
|
|
|
|
auto_node_.swap_nodes(other.auto_node_);
|
2007-05-04 21:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
2008-04-27 15:03:06 +00:00
|
|
|
bool is_linked() const
|
|
|
|
|
{
|
2008-12-13 13:49:31 +00:00
|
|
|
return Hooks::base_hook_type::is_linked() ||
|
|
|
|
|
Hooks::auto_base_hook_type::is_linked() ||
|
|
|
|
|
node_.is_linked() ||
|
|
|
|
|
auto_node_.is_linked();
|
2008-04-27 15:03:06 +00:00
|
|
|
}
|
|
|
|
|
|
2007-05-04 21:30:54 +00:00
|
|
|
~testvalue()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
bool operator< (const testvalue &other) const
|
|
|
|
|
{ return value_ < other.value_; }
|
|
|
|
|
|
|
|
|
|
bool operator==(const testvalue &other) const
|
|
|
|
|
{ return value_ == other.value_; }
|
2007-05-12 12:34:55 +00:00
|
|
|
|
2008-07-08 17:00:24 +00:00
|
|
|
bool operator!=(const testvalue &other) const
|
|
|
|
|
{ return value_ != other.value_; }
|
|
|
|
|
|
2007-05-12 12:34:55 +00:00
|
|
|
friend bool operator< (int other1, const testvalue &other2)
|
|
|
|
|
{ return other1 < other2.value_; }
|
|
|
|
|
|
|
|
|
|
friend bool operator< (const testvalue &other1, int other2)
|
|
|
|
|
{ return other1.value_ < other2; }
|
|
|
|
|
|
|
|
|
|
friend bool operator== (int other1, const testvalue &other2)
|
|
|
|
|
{ return other1 == other2.value_; }
|
|
|
|
|
|
|
|
|
|
friend bool operator== (const testvalue &other1, int other2)
|
|
|
|
|
{ return other1.value_ == other2; }
|
2008-07-08 17:00:24 +00:00
|
|
|
|
|
|
|
|
friend bool operator!= (int other1, const testvalue &other2)
|
|
|
|
|
{ return other1 != other2.value_; }
|
|
|
|
|
|
|
|
|
|
friend bool operator!= (const testvalue &other1, int other2)
|
|
|
|
|
{ return other1.value_ != other2; }
|
2007-05-04 21:30:54 +00:00
|
|
|
};
|
|
|
|
|
|
2008-12-13 13:49:31 +00:00
|
|
|
template<class Hooks, bool ConstantTimeSize>
|
|
|
|
|
std::size_t hash_value(const testvalue<Hooks, ConstantTimeSize> &t)
|
2007-05-04 21:30:54 +00:00
|
|
|
{
|
|
|
|
|
boost::hash<int> hasher;
|
|
|
|
|
return hasher(t.value_);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-13 13:49:31 +00:00
|
|
|
template<class Hooks, bool ConstantTimeSize>
|
2009-10-14 13:08:04 +00:00
|
|
|
bool priority_order( const testvalue<Hooks, ConstantTimeSize> &t1
|
|
|
|
|
, const testvalue<Hooks, ConstantTimeSize> &t2)
|
2008-12-13 13:49:31 +00:00
|
|
|
{
|
|
|
|
|
std::size_t hash1 = hash_value(t1);
|
2009-10-14 13:08:04 +00:00
|
|
|
boost::hash_combine(hash1, &t1);
|
2008-12-13 13:49:31 +00:00
|
|
|
std::size_t hash2 = hash_value(t2);
|
2009-10-14 13:08:04 +00:00
|
|
|
boost::hash_combine(hash2, &t2);
|
2008-12-13 13:49:31 +00:00
|
|
|
return hash1 < hash2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Hooks, bool constant_time_size>
|
2007-05-04 21:30:54 +00:00
|
|
|
std::ostream& operator<<
|
2008-12-13 13:49:31 +00:00
|
|
|
(std::ostream& s, const testvalue<Hooks, constant_time_size>& t)
|
2007-05-04 21:30:54 +00:00
|
|
|
{ return s << t.value_; }
|
|
|
|
|
|
|
|
|
|
struct even_odd
|
|
|
|
|
{
|
2008-12-13 13:49:31 +00:00
|
|
|
template<class Hooks, bool constant_time_size>
|
2007-05-04 21:30:54 +00:00
|
|
|
bool operator()
|
2008-12-13 13:49:31 +00:00
|
|
|
(const testvalue<Hooks, constant_time_size>& v1
|
|
|
|
|
,const testvalue<Hooks, constant_time_size>& v2) const
|
2007-05-04 21:30:54 +00:00
|
|
|
{
|
|
|
|
|
if ((v1.value_ & 1) == (v2.value_ & 1))
|
|
|
|
|
return v1.value_ < v2.value_;
|
|
|
|
|
else
|
|
|
|
|
return v2.value_ & 1;
|
2012-07-12 07:21:17 +00:00
|
|
|
}
|
2007-05-04 21:30:54 +00:00
|
|
|
};
|
|
|
|
|
|
2008-01-25 23:07:51 +00:00
|
|
|
struct is_even
|
|
|
|
|
{
|
2008-12-13 13:49:31 +00:00
|
|
|
template<class Hooks, bool constant_time_size>
|
2008-01-25 23:07:51 +00:00
|
|
|
bool operator()
|
2008-12-13 13:49:31 +00:00
|
|
|
(const testvalue<Hooks, constant_time_size>& v1) const
|
2012-07-12 07:21:17 +00:00
|
|
|
{ return (v1.value_ & 1) == 0; }
|
2008-01-25 23:07:51 +00:00
|
|
|
};
|
2009-10-14 13:08:04 +00:00
|
|
|
/*
|
|
|
|
|
struct int_testvalue_comp
|
|
|
|
|
{
|
|
|
|
|
template<class Hooks, bool constant_time_size>
|
|
|
|
|
bool operator()
|
|
|
|
|
(const testvalue<Hooks, constant_time_size>& v1, const int &i) const
|
|
|
|
|
{ return v1.value_ < i; }
|
|
|
|
|
template<class Hooks, bool constant_time_size>
|
|
|
|
|
bool operator()
|
|
|
|
|
(const int &i, const testvalue<Hooks, constant_time_size>& v1) const
|
|
|
|
|
{ return i < v1.value_; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct int_testvalue_pcomp
|
|
|
|
|
{
|
|
|
|
|
template<class Hooks, bool constant_time_size>
|
|
|
|
|
bool operator()
|
|
|
|
|
(const testvalue<Hooks, constant_time_size>& v1, const int &i) const
|
|
|
|
|
{ return v1.value_ < i; }
|
|
|
|
|
template<class Hooks, bool constant_time_size>
|
|
|
|
|
bool operator()
|
|
|
|
|
(const int &i, const testvalue<Hooks, constant_time_size>& v1) const
|
|
|
|
|
{ return i < v1.value_; }
|
|
|
|
|
};
|
|
|
|
|
*/
|
2008-01-25 23:07:51 +00:00
|
|
|
|
2007-05-04 21:30:54 +00:00
|
|
|
} //namespace boost{
|
|
|
|
|
} //namespace intrusive{
|
|
|
|
|
|
|
|
|
|
#endif
|