Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Doesn't this approach violate object's constancy?</p> </blockquote> <p>No. Yes. Maybe. It obviously does not affect <em>syntactic</em> constancy, since the compiler does not complain. This is because syntactic constancy requires the object and its members, in this case especially the smart pointer, to be const. It does <em>not</em> require the pointee (i.e. the array of deques) to be const.<br> The <em>semantic</em> constancy is another thing. If the array belongs to your object, changing the array means changing the object, and having the object const means not changing the array. It's up to you to enforce semantic constness that is not syntactic constness. However, in such a case I would not use a <code>shared_ptr</code> but a <code>std::vector</code>, because that's expressing single ownership, while <code>shared_ptr</code> is shared ownership - obviously. In addition, <code>std::vector</code> is designed to enforce semantic constancy, meaning the library implementors enforced the contained elements to be const in a const vector.<br> However, since I don't know the context of your class and the deque array, and since you use <code>shared_ptr</code> wich explicitly means shared ownership, <em>maybe</em> you need semantic constness, maybe not.</p> <p><strong>But</strong> since you said you want a read-only access and you return by value, that access won't change the array contents, sou you might be well. Returning by const reference might do what you need too, plus it avoids unnecessary temporary copies wich might be quite expensive depending on how many objects the dequeues store</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload