<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>According to standard n3242 about std::allocator<<font class="Apple-style-span" color="#00d008">T</font>> :</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "></div></div><blockquote type="cite"><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">17.6.3.5<span class="Apple-tab-span" style="white-space:pre">  </span>Allocator requirements<span class="Apple-tab-span" style="white-space:pre">      </span>[allocator.requirements]</div></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">...</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" color="#00cb08">T</font><span class="Apple-tab-span" style="white-space:pre">        </span>any non-const, non-reference object type</div></div></blockquote><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><span class="Apple-style-span" style="font-size: medium; ">But, I haven't seen any similar constness requirement with the faulty constructor template argument </span><span class="Apple-style-span" style="color: rgb(0, 191, 7); ">Y </span><span class="Apple-style-span" style="font-size: medium; ">: <font class="Apple-style-span" color="#c63726">shared_ptr<T>::shared_ptr</font><font class="Apple-style-span" color="#c63726">(</font></span><span class="Apple-style-span" style="color: rgb(0, 191, 7); font-size: medium; ">Y</span><span class="Apple-style-span" style="font-size: medium; "><font class="Apple-style-span" color="#c63726"> *p)</font></span><span class="Apple-style-span" style="font-size: medium; ">.</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3"><br></font></div><blockquote type="cite"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 9px/normal Helvetica; ">template<class Y> explicit shared_ptr(Y* p);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><span style="font: 8.0px Helvetica">3<span class="Apple-tab-span" style="white-space:pre">        </span></span>Requires: p shall be convertible to T*. Y shall be a complete type. The expression delete p shall be well formed, shall have well defined behavior, and shall not throw exceptions.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><span style="font: 8.0px Helvetica">4<span class="Apple-tab-span" style="white-space:pre"> </span></span>Effects: Constructs a shared_ptr object that owns the pointer p.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><span style="font: 8.0px Helvetica">5<span class="Apple-tab-span" style="white-space:pre">    </span></span>Postconditions: use_count() == 1 && get() == p.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><span style="font: 8.0px Helvetica">6<span class="Apple-tab-span" style="white-space:pre">     </span></span>Throws: bad_alloc, or an implementation-defined exception when a resource other than memory could not be obtained.</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><span style="font: 8.0px Helvetica">7<span class="Apple-tab-span" style="white-space:pre">  </span></span>Exception safety: If an exception is thrown, delete p is called.</div></font></div></blockquote><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><br></div><span class="Apple-style-span" style="font-size: medium; ">Is it acceptable to remove const from template argument ?</span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><span class="Apple-style-span" style="font-size: medium; "><br></span></div><blockquote type="cite"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3">template<class _Tp> </font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3">template<class _Yp> </font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3">shared_ptr<_Tp>::shared_ptr(_Yp* __p) </font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3">    : __ptr_(__p)</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3">{</font></div></font></div></font></div></blockquote><blockquote type="cite">    <font class="Apple-style-span" color="#59a773">typedef std::remove_const<_Yp>::type _Ypi;</font><br></blockquote><blockquote type="cite"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3">    unique_ptr<<font class="Apple-style-span" color="#59a770">_Ypi</font>> __hold(__p);</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3">    typedef __shared_ptr_pointer<<font class="Apple-style-span" color="#5aa76e">_Ypi</font>*, default_delete<<font class="Apple-style-span" color="#5ca76c">_Ypi</font>>, allocator<<font class="Apple-style-span" color="#65a773">_Ypi</font>> > _CntrlBlk;</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3">    __cntrl_ = new _CntrlBlk(__p, default_delete<<font class="Apple-style-span" color="#63a76b">_Ypi</font>>(), allocator<<font class="Apple-style-span" color="#67a774">_Ypi</font>>());</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3">    __hold.release();</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3">    __enable_weak_this(__p);</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3">}</font></div></font></div></font></div></blockquote><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3"><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><font class="Apple-style-span" size="3"><div><br></div></font></div></font><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Helvetica; ">On Jan 2, 2012, at 8:21 AM, <a href="mailto:redballoon36@gmail.com">redballoon36@gmail.com</a> wrote:</div></div><div><br class="Apple-interchange-newline"><blockquote type="cite">(Howard: Sorry, I hadn't meant to send that email just yet.)<br><br><div>I'm attempting to get Cinder (<a href="http://libcinder.org/" target="_blank">libcinder.org</a>) to compile with libc++.  It uses things like std::shared_ptr<const __CFDictionary>, which is returned const from CFDictionaryCreate(...).  There's no need to modify the resulting Dictionary (and they are immutable anyway?), so it makes sense to keep the value const.  Thinking "aloud," I could have a GUI element that uses a shared_ptr to reference a color from the user's preferences in order to draw itself, that the GUI element shouldn't ever modify, so the value should be const.  This way, when the GUI dies, the shared_ptr does it thing and cleans up the color.</div>

<div><br></div><div>In terms of fixes, the thing that causes this is that a const type is passed into the shared_ptr.  Removing the const where the shared_ptr instantiates the allocator should also fix this.  Similarly the const-ness could be removed(cast/type_trait-ed) in the Cinder code, avoiding any changes to the library.</div>

<div><br></div><div>At this point, though, I'm arguing with the standard, so I lose for now.  I'll get you next time, C++!</div><div><br></div><div>Thanks,</div><div>Paul O'Neil</div><div><br><div class="gmail_quote">

On Mon, Jan 2, 2012 at 1:55 AM, Paul O'Neil <span dir="ltr"><<a href="mailto:redballoon36@gmail.com">redballoon36@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


  

    
  
  <div bgcolor="#FFFFFF" text="#000000">
    I'm attempting to get Cinder (<a href="http://libcinder.org/" target="_blank">libcinder.org</a>)
    to compile with libc++.  It uses a std::shared_ptr<const
    __CFDictionary>, which is returned from CFDictionaryCreate(...).<br>
    <br>
    <div class="gmail_quote"><div class="im">On Sun, Jan 1, 2012 at 10:35 PM, Howard
      Hinnant <span dir="ltr"><<a href="mailto:hhinnant@apple.com" target="_blank">hhinnant@apple.com</a>></span>
      wrote:<br>
      </div><div><div class="h5"><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">The C11++ std
        says that std::allocator<T> contains both of these
        members:<br>
        <br>
        <br>
           pointer address(reference x) const noexcept;<br>
           const_pointer address(const_reference x) const noexcept;<br>
        <br>
        And when T is const, these two members result in a double
        declaration of the same member.  So according to the standard,
        std::allocator<const T> isn't supposed to work.<br>
        <br>
        But let's explore beyond that.<br>
        <br>
        What is your use case for needing to do so?  Perhaps if it is
        motivating, and there is no easy workaround, libc++ could
        support it as an extension.<br>
        <span><font color="#888888"><br>
            Howard<br>
          </font></span>
        <div>
          <div><br>
            On Jan 1, 2012, at 10:01 PM, <a href="mailto:redballoon36@gmail.com" target="_blank">redballoon36@gmail.com</a>
            wrote:<br>
            <br>
            > Thanks for the response.<br>
            ><br>
            > Yes, that compiles.  Is there a reason that keeping the
            const doesn't work?  Given that you say this isn't allowed,
            why is it a bad idea?  The shared_ptr provided by boost
            takes this.<br>
            ><br>
            > I did some more digging in the Buzilla (I had only
            searched open bugs before), and found this one: <a href="http://llvm.org/bugs/show_bug.cgi?id=8421" target="_blank">http://llvm.org/bugs/show_bug.cgi?id=8421</a>
            .  It looks like the same thing, but in std::map instead.
            Also since emailing the list, I tried it in Visual Studio
            2010 and it compiled without errors.  However, I have no
            idea how to work Visual Studio, so some the settings may
            have been very different.<br>
            ><br>
            > Thanks again,<br>
            > Paul O'Neil<br>
            ><br>
            > On Sun, Jan 1, 2012 at 8:12 PM, David Keller <<a href="mailto:david.keller@litchis.fr" target="_blank">david.keller@litchis.fr</a>>
            wrote:<br>
            > Hi,<br>
            ><br>
            > You may write:<br>
            ><br>
            >> std::shared_ptr<const int> ptr(new int(4));<br>
            ><br>
            > Regards<br>
            ><br>
            > On Dec 30, 2011, at 1:29 AM, <a href="mailto:redballoon36@gmail.com" target="_blank">redballoon36@gmail.com</a>
            wrote:<br>
            ><br>
            >> Hello,<br>
            >><br>
            >> I've encountered a compiler error using shared_ptr
            and allocator from the libc++ header <memory>.  I'm
            running OS X 10.7.2, and I first noticed this while using
            the libc++ implementation with Xcode 4.2.1, though I believe
            this still exists in svn 147357.<br>
            >><br>
            >> The problem is caused by instantiating
            std::allocator<> (in the memory header) with a const
            type.  This causes the pointer and const_pointer types to be
            the same, which results in methods using these to have the
            same signatures, which gives a compiler error (as it should,
            given that methods are colliding).  Is this supposed to
            happen? I haven't read the standard, but it seems like it
            should work, that is, that std::allocator<const int>
            should be allowed to exist.<br>
            >><br>
            >> A bit of background. This gets triggered when
            using:<br>
            >> std::shared_ptr<const int> ptr(new const
            int(4));<br>
            >> which also seems like a reasonable thing to do.<br>
            >><br>
            >> Thanks,<br>
            >> Paul O'Neil<br>
            >> _______________________________________________<br>
            >> cfe-dev mailing list<br>
            >> <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
            >> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
            ><br>
            ><br>
            > _______________________________________________<br>
            > cfe-dev mailing list<br>
            > <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
            > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
            <br>
          </div>
        </div>
      </blockquote>
    </div></div></div>
    <br>
    <br>
  </div>

</blockquote></div><br></div>
_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev<br></blockquote></div><br></body></html>