3
votes

I tried to use boost::lockfree:queue to queue iterators, but the compilation fails on the static_assert (Debug Mode only)

boost::has_trivial_destructor::value

and

boost::has_trivial_assign::value

Code:

using list_it_t = typename std::list<Elem<T, dimens>>::iterator;
[...]
boost::lockfree::queue<list_it_t> iterators(1024);

Where Elem is a POD type, but afaik the behaviour is reproducible with other iterators as well.

I always thought that iterators fullfil both conditions?! In what way are they not trivially assignable or destructable?

Can I somehow still work with iterators or do I have to change to pointers on the elements? I'm iterating over the list and pushing iterators on the queue to be processed by other threads.

Specification:

  • MSVC v141
  • Boost 1.65
1

1 Answers

2
votes

The only requirement for std::list::iterator is it must be a BidirectionalIterator. So yes, a Standard Library implementation can choose to have non-trivial constructor, destructor, assignment operator ...

One can only assume the implementation choose to define such special functions to provide maybe debug checks or information.

If you get a look at an example implementation of std::list, you will find line #122...

00110   template<typename _Tp>
00111     struct _List_iterator
00112     {
00113       typedef _List_iterator<_Tp>           _Self;
00114       typedef _List_node<_Tp>               _Node;
00115 
00116       typedef ptrdiff_t                     difference_type;
00117       typedef bidirectional_iterator_tag    iterator_category;
00118       typedef _Tp                           value_type;
00119       typedef _Tp*                          pointer;
00120       typedef _Tp&                          reference;
00121 
00122       _List_iterator()
00123       : _M_node() { }
00124 
00125       _List_iterator(_List_node_base* __x)
00126       : _M_node(__x) { }
...
00175       // The only member points to the %list element.
00176       _List_node_base* _M_node;
00177     };

... a user-provided constructor to provide better failures I guess.