Boost C++ Libraries: Ticket #7378: lookup_one_property fails if property tag not found
https://svn.boost.org/trac10/ticket/7378
<p>
<code>boost::lookup_one_property<PropertyList,Tag>::found</code> does not compile if <code>Tag</code> is not found in the <code>PropertyList</code>.
</p>
<p>
The problem originates from the <code>lookup(...)</code> function definition in the template specialization
</p>
<pre class="wiki"> template <typename Tag, typename T, typename Base, typename PropName>
struct lookup_one_property_internal<boost::property<Tag, T, Base>, PropName>: lookup_one_property_internal<Base, PropName> {
private:
typedef lookup_one_property_internal<Base, PropName> base_type;
public:
template <typename PL>
static typename enable_if<is_same<PL, boost::property<Tag, T, Base> >, typename base_type::type&>::type
lookup(PL& prop, const PropName& tag)
</pre><p>
which requires the base class to provide a <code>type</code> member.
</p>
<p>
If the tag is not found the unspecialized template
</p>
<pre class="wiki"> template <typename PList, typename PropName, typename Enable = void>
struct lookup_one_property_internal {BOOST_STATIC_CONSTANT(bool, found = false);};
</pre><p>
will be instantiated as Base where the compiler can't find any <code>type</code> member.
</p>
en-usBoost C++ Libraries/htdocs/site/boost.png
https://svn.boost.org/trac10/ticket/7378
Trac 1.4.3Andreas Hehn <hehn@…>Fri, 14 Sep 2012 15:42:37 GMTattachment set
https://svn.boost.org/trac10/ticket/7378
https://svn.boost.org/trac10/ticket/7378
<ul>
<li><strong>attachment</strong>
→ <span class="trac-field-new">example.cpp</span>
</li>
</ul>
<p>
demonstration code
</p>
TicketJeremiah WillcockFri, 14 Sep 2012 15:45:53 GMTstatus, component changed; resolution set
https://svn.boost.org/trac10/ticket/7378#comment:1
https://svn.boost.org/trac10/ticket/7378#comment:1
<ul>
<li><strong>status</strong>
<span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span>
</li>
<li><strong>resolution</strong>
→ <span class="trac-field-new">wontfix</span>
</li>
<li><strong>component</strong>
<span class="trac-field-old">property_map</span> → <span class="trac-field-new">graph</span>
</li>
</ul>
<p>
That change was made on purpose; it greatly helps error messages for using nonexistent property maps from graphs.
</p>
TicketAndreas Hehn <hehn@…>Fri, 14 Sep 2012 15:45:56 GMTattachment set
https://svn.boost.org/trac10/ticket/7378
https://svn.boost.org/trac10/ticket/7378
<ul>
<li><strong>attachment</strong>
→ <span class="trac-field-new">property.hpp.patch</span>
</li>
</ul>
<p>
patch
</p>
TicketAndreas Hehn <hehn@…>Fri, 14 Sep 2012 15:52:52 GMT
<link>https://svn.boost.org/trac10/ticket/7378#comment:2 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7378#comment:2</guid>
<description>
<p>
Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7378#comment:1" title="Comment 1">jewillco</a>:
</p>
<blockquote class="citation">
<p>
That change was made on purpose; it greatly helps error messages for using nonexistent property maps from graphs.
</p>
</blockquote>
<p>
Is there another way of checking the existence of some particular property tag then?
</p>
</description>
<category>Ticket</category>
</item>
<item>
<dc:creator>Jeremiah Willcock</dc:creator>
<pubDate>Fri, 14 Sep 2012 15:57:08 GMT</pubDate>
<title/>
<link>https://svn.boost.org/trac10/ticket/7378#comment:3 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7378#comment:3</guid>
<description>
<p>
Look at <code>lookup_one_property<...>::found</code>. That takes a property list and a tag and determines if the property is present in the list. That doesn't give an easy way to test a graph for a given property, though.
</p>
</description>
<category>Ticket</category>
</item>
<item>
<dc:creator>anonymous</dc:creator>
<pubDate>Fri, 14 Sep 2012 16:01:38 GMT</pubDate>
<title/>
<link>https://svn.boost.org/trac10/ticket/7378#comment:4 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7378#comment:4</guid>
<description>
<p>
That's what I thought, but <code>lookup_one_property<...>::found</code> is not <code>false</code> if the tag is not found, instead it just results in a compiler error.
</p>
</description>
<category>Ticket</category>
</item>
<item>
<dc:creator>Jeremiah Willcock</dc:creator>
<pubDate>Fri, 14 Sep 2012 16:03:40 GMT</pubDate>
<title/>
<link>https://svn.boost.org/trac10/ticket/7378#comment:5 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7378#comment:5</guid>
<description>
<p>
What triggers the error in that case?
</p>
</description>
<category>Ticket</category>
</item>
<item>
<author>Andreas Hehn <hehn@…></author>
<pubDate>Fri, 14 Sep 2012 16:06:03 GMT</pubDate>
<title/>
<link>https://svn.boost.org/trac10/ticket/7378#comment:6 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7378#comment:6</guid>
<description>
<p>
That's what I reported in this bug report. Or am I missing something?
</p>
</description>
<category>Ticket</category>
</item>
<item>
<author>Andreas Hehn <hehn@…></author>
<pubDate>Fri, 14 Sep 2012 17:55:51 GMT</pubDate>
<title/>
<link>https://svn.boost.org/trac10/ticket/7378#comment:7 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7378#comment:7</guid>
<description>
<p>
The problem is that in the enable_if of the lookup(...) member function
</p>
<pre class="wiki">template <typename Tag, typename T, typename Base, typename PropName>
struct lookup_one_property_internal<boost::property<Tag, T, Base>, PropName>: lookup_one_property_internal<Base, PropName> {
private:
typedef lookup_one_property_internal<Base, PropName> base_type;
public:
template <typename PL>
static typename enable_if<is_same<PL, boost::property<Tag, T, Base> >, typename base_type::type&>::type
lookup(PL& prop, const PropName& tag)
</pre><p>
typename base_type::type& does not depend on the template parameter of the template member function but only on the template parameters of the class. Therefore base_type::type is required to exist, even if lookup(...) is not used (or the enable_if<...> disables the function).
</p>
<p>
A solution could be to add a indirection which depeneds on <code>PL</code>, like
</p>
<pre class="wiki"> template <class First, class Second>
struct second_type {
typedef Second type;
};
...
static typename enable_if<is_same<PL, boost::property<Tag, T, Base> >, typename second_type<PL,base_type>::type::type&>::type
lookup(PL& prop, const PropName& tag)
</pre><p>
which will prevent the compiler from resolving base_type::type unless lookup(...) is explicitly instantiated.
</p>
<p>
This way the general template <code>lookup_one_property_internal</code> does not need to define a <code>type</code> member to use <code>lookup_one_property<...>::found</code>.
</p>
<p>
But I have to admit that this solution looks a little ugly.
</p>
</description>
<category>Ticket</category>
</item>
<item>
<dc:creator>Jeremiah Willcock</dc:creator>
<pubDate>Fri, 14 Sep 2012 18:04:04 GMT</pubDate>
<title/>
<link>https://svn.boost.org/trac10/ticket/7378#comment:8 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7378#comment:8</guid>
<description>
<p>
(In <a class="changeset" href="https://svn.boost.org/trac10/changeset/80524" title="Added void as default value of lookup_one_property_internal::type for ...">[80524]</a>) Added void as default value of lookup_one_property_internal::type for "not found"; refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7378" title="#7378: Bugs: lookup_one_property fails if property tag not found (closed: fixed)">#7378</a>
</p>
</description>
<category>Ticket</category>
</item>
<item>
<author>Andreas Hehn <hehn@…></author>
<pubDate>Fri, 14 Sep 2012 21:29:02 GMT</pubDate>
<title>status changed; resolution deleted
https://svn.boost.org/trac10/ticket/7378#comment:9
https://svn.boost.org/trac10/ticket/7378#comment:9
<ul>
<li><strong>status</strong>
<span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span>
</li>
<li><strong>resolution</strong>
<span class="trac-field-deleted">wontfix</span>
</li>
</ul>
<p>
This was also my first approach, but unfortunately it doesn't solve the problem.
</p>
<p>
Since the return type of <code>lookup(...)</code> is <code>type&</code> the compiler will complain if <code>type</code> is <code>void</code>, as you can see if you try to compile my example code.
</p>
TicketJeremiah WillcockFri, 14 Sep 2012 21:41:09 GMTstatus changed; resolution set
https://svn.boost.org/trac10/ticket/7378#comment:10
https://svn.boost.org/trac10/ticket/7378#comment:10
<ul>
<li><strong>status</strong>
<span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span>
</li>
<li><strong>resolution</strong>
→ <span class="trac-field-new">fixed</span>
</li>
</ul>
<p>
(In <a class="changeset" href="https://svn.boost.org/trac10/changeset/80528" title="Using lazy_enable_if to avoid "reference to void" errors for ...">[80528]</a>) Using lazy_enable_if to avoid "reference to void" errors for properties that are not found; fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7378" title="#7378: Bugs: lookup_one_property fails if property tag not found (closed: fixed)">#7378</a>
</p>
TicketAndreas Hehn <hehn@…>Sat, 15 Sep 2012 11:50:06 GMT
<link>https://svn.boost.org/trac10/ticket/7378#comment:11 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7378#comment:11</guid>
<description>
<p>
Great! That solved the problem. I totally forgot about lazy_enable_if...
</p>
<p>
Could you also apply the same fix to <code>struct lookup_one_property<const T, Tag></code> in line 159 of the same file?
</p>
<p>
Thanks for fixing the problem so quickly! :)
</p>
</description>
<category>Ticket</category>
</item>
<item>
<dc:creator>Jeremiah Willcock</dc:creator>
<pubDate>Sat, 15 Sep 2012 13:49:06 GMT</pubDate>
<title/>
<link>https://svn.boost.org/trac10/ticket/7378#comment:12 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7378#comment:12</guid>
<description>
<p>
(In <a class="changeset" href="https://svn.boost.org/trac10/changeset/80532" title="Further fixed #7378 issue; refs #7378">[80532]</a>) Further fixed <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7378" title="#7378: Bugs: lookup_one_property fails if property tag not found (closed: fixed)">#7378</a> issue; refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7378" title="#7378: Bugs: lookup_one_property fails if property tag not found (closed: fixed)">#7378</a>
</p>
</description>
<category>Ticket</category>
</item>
</channel>
</rss>