From ea682642160b3a22c3b88bbb575fe8aeea14dad7 Mon Sep 17 00:00:00 2001 From: Jeremy Siek Date: Tue, 3 Oct 2000 02:56:51 +0000 Subject: [PATCH] added same_property and property copy constructor put alternate form of property usage in edge_property.cpp [SVN r7891] --- examples/edge_property.cpp | 44 +++++++++++++++++++++++ include/boost/pending/detail/property.hpp | 28 +++++++++++---- include/boost/pending/property.hpp | 12 ++++--- 3 files changed, 72 insertions(+), 12 deletions(-) diff --git a/examples/edge_property.cpp b/examples/edge_property.cpp index 9098b8ff..92c9adbb 100644 --- a/examples/edge_property.cpp +++ b/examples/edge_property.cpp @@ -25,6 +25,45 @@ // // Sample output: // +// 0 --(8, 10)--> 1 +// +// 1 --(12, 20)--> 4 --(12, 40)--> 3 +// <--(8,10)-- 0 <--(16,20)-- 2 +// 2 --(16, 20)--> 1 +// <--(16,20)-- 5 +// 3 --(12, 40)--> 6 +// <--(12,40)-- 1 +// 4 --(12, 20)--> 7 +// <--(12,20)-- 1 +// 5 --(16, 20)--> 2 +// <--(16,20)-- 6 +// 6 --(16, 20)--> 5 --(8, 10)--> 8 +// <--(12,20)-- 7 <--(12,40)-- 3 +// 7 --(12, 20)--> 6 +// <--(12,20)-- 4 +// 8 +// <--(8,10)-- 6 +// +// +// 0 --(8, 1)--> 1 +// +// 1 --(12, 2)--> 4 --(12, 3)--> 3 +// <--(8,1)-- 0 <--(16,4)-- 2 +// 2 --(16, 4)--> 1 +// <--(16,7)-- 5 +// 3 --(12, 5)--> 6 +// <--(12,3)-- 1 +// 4 --(12, 6)--> 7 +// <--(12,2)-- 1 +// 5 --(16, 7)--> 2 +// <--(16,8)-- 6 +// 6 --(16, 8)--> 5 +// <--(12,10)-- 7 <--(12,5)-- 3 +// 7 --(12, 10)--> 6 +// <--(12,6)-- 4 +// 8 +// + #include #include @@ -36,6 +75,7 @@ using namespace boost; using namespace std; +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION enum edge_flow_t { edge_flow = 100 }; enum edge_capacity_t { edge_capacity = 101 }; @@ -43,6 +83,10 @@ namespace boost { BOOST_INSTALL_PROPERTY(edge, flow); BOOST_INSTALL_PROPERTY(edge, capacity); } +#else +struct edge_flow_t { typedef edge_property_tag kind; } edge_flow; +struct edge_capacity_t { typedef edge_property_tag kind; } edge_capacity; +#endif template void print_network(Graph& G, Capacity capacity, Flow flow) diff --git a/include/boost/pending/detail/property.hpp b/include/boost/pending/detail/property.hpp index ea4a7cd7..00cd4c30 100644 --- a/include/boost/pending/detail/property.hpp +++ b/include/boost/pending/detail/property.hpp @@ -7,6 +7,23 @@ namespace boost { namespace detail { +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + template + struct same_property { + enum { value = int(property_num::value) + == int(property_num::value) }; + }; +#else + template + struct same_property { + enum { value = false }; + }; + template + struct same_property { + enum { value = true }; + }; +#endif + template struct property_value_dispatch { }; @@ -27,8 +44,7 @@ namespace boost { static T& get_value(Property& p, T t, Tag tag) { typedef typename Property::next_type Next; typedef typename Next::tag_type Next_tag; - enum { match = int(property_num::value) - == int(property_num::value) }; + enum { match = same_property::value }; return property_value_dispatch ::get_value(static_cast(p), t, tag); } @@ -36,8 +52,7 @@ namespace boost { static const T& const_get_value(const Property& p, T t, Tag tag) { typedef typename Property::next_type Next; typedef typename Next::tag_type Next_tag; - enum { match = int(property_num::value) - == int(property_num::value) }; + enum { match = same_property::value }; return property_value_dispatch ::const_get_value(static_cast(p), t, tag); } @@ -95,11 +110,10 @@ namespace boost { typedef typename TagValueAList::first_type AListFirst; typedef typename AListFirst::first_type Tag2; typedef typename AListFirst::second_type Value; - enum { tag1 = property_num::value, - tag2 = property_num::value }; + enum { match = same_property::value }; typedef typename TagValueAList::second_type Next; typedef typename ev_selector::type Extractor; - typedef typename boost::ct_if< (tag1==tag2), Value, + typedef typename boost::ct_if< match, Value, typename Extractor::template bind::type >::type type; }; diff --git a/include/boost/pending/property.hpp b/include/boost/pending/property.hpp index 7beb1a50..5c18a6fb 100644 --- a/include/boost/pending/property.hpp +++ b/include/boost/pending/property.hpp @@ -16,12 +16,13 @@ namespace boost { typedef Tag tag_type; typedef T value_type; property() { } + property(const property& x) : Base(x), m_value(x.m_value) { } property(const T& v) : m_value(v) { } property(const T& v, const Base& b) : Base(b), m_value(v) { } T m_value; }; - // The BGL properties just specialize property_kind and + // The BGL properties specialize property_kind and // property_num, and use enum's for the Property type (see // graph/properties.hpp), but the user may want to use a class // instead with a nested kind type and num. Also, we may want to @@ -32,6 +33,9 @@ namespace boost { typedef typename Property::kind type; }; + // The property_num is only needed for no partial spec. workaround + // in detail::same_property. + template struct property_num { enum { value = Property::num }; @@ -47,16 +51,14 @@ namespace boost { template inline T2& get_property_value(property& p, T2 t2, Tag2 tag2) { - enum { match = int(property_num::value) - == int(property_num::value) }; + enum { match = detail::same_property::value }; typedef detail::property_value_dispatch Dispatcher; return Dispatcher::get_value(p, t2, tag2); } template inline const T2& get_property_value(const property& p, T2 t2, Tag2 tag2) { - enum { match = int(property_num::value) - == int(property_num::value) }; + enum { match = detail::same_property::value }; typedef detail::property_value_dispatch Dispatcher; return Dispatcher::const_get_value(p, t2, tag2); }