|
14 | 14 | #include <boost/interprocess/detail/config_begin.hpp> |
15 | 15 | #include <boost/interprocess/detail/workaround.hpp> |
16 | 16 | #include <boost/move/utility_core.hpp> |
| 17 | +#include <boost/container/detail/type_traits.hpp> //alignment_of, aligned_storage |
17 | 18 |
|
18 | 19 | namespace boost { |
19 | 20 | namespace interprocess { |
@@ -287,6 +288,84 @@ class non_copymovable_int |
287 | 288 | int m_int; |
288 | 289 | }; |
289 | 290 |
|
| 291 | + |
| 292 | +class overaligned_copyable_int |
| 293 | +{ |
| 294 | + public: |
| 295 | + overaligned_copyable_int() |
| 296 | + { |
| 297 | + m_d.m_int = 0; |
| 298 | + } |
| 299 | + |
| 300 | + explicit overaligned_copyable_int(int a) |
| 301 | + { |
| 302 | + m_d.m_int = a; |
| 303 | + } |
| 304 | + |
| 305 | + overaligned_copyable_int(const overaligned_copyable_int& mmi) |
| 306 | + { |
| 307 | + m_d.m_int = mmi.m_d.m_int; |
| 308 | + } |
| 309 | + |
| 310 | + overaligned_copyable_int & operator= (int i) |
| 311 | + { this->m_d.m_int = i; return *this; } |
| 312 | + |
| 313 | + overaligned_copyable_int & operator=(const overaligned_copyable_int& mmi) |
| 314 | + { m_d.m_int = mmi.m_d.m_int; return *this; } |
| 315 | + |
| 316 | + bool operator ==(const overaligned_copyable_int &mi) const |
| 317 | + { return this->m_d.m_int == mi.m_d.m_int; } |
| 318 | + |
| 319 | + bool operator !=(const overaligned_copyable_int &mi) const |
| 320 | + { return this->m_d.m_int != mi.m_d.m_int; } |
| 321 | + |
| 322 | + bool operator <(const overaligned_copyable_int &mi) const |
| 323 | + { return this->m_d.m_int < mi.m_d.m_int; } |
| 324 | + |
| 325 | + bool operator <=(const overaligned_copyable_int &mi) const |
| 326 | + { return this->m_d.m_int <= mi.m_d.m_int; } |
| 327 | + |
| 328 | + bool operator >=(const overaligned_copyable_int &mi) const |
| 329 | + { return this->m_d.m_int >= mi.m_d.m_int; } |
| 330 | + |
| 331 | + bool operator >(const overaligned_copyable_int &mi) const |
| 332 | + { return this->m_d.m_int > mi.m_d.m_int; } |
| 333 | + |
| 334 | + int get_int() const |
| 335 | + { return m_d.m_int; } |
| 336 | + |
| 337 | + friend bool operator==(const overaligned_copyable_int &l, int r) |
| 338 | + { return l.get_int() == r; } |
| 339 | + |
| 340 | + friend bool operator==(int l, const overaligned_copyable_int &r) |
| 341 | + { return l == r.get_int(); } |
| 342 | + |
| 343 | + private: |
| 344 | + |
| 345 | + union data |
| 346 | + { |
| 347 | + boost::container::dtl::aligned_storage<sizeof(int), 64>::type aligner; |
| 348 | + int m_int; |
| 349 | + } m_d; |
| 350 | +}; |
| 351 | + |
| 352 | +template<class E, class T> |
| 353 | +std::basic_ostream<E, T> & operator<< |
| 354 | + (std::basic_ostream<E, T> & os, overaligned_copyable_int const & p) |
| 355 | + |
| 356 | +{ |
| 357 | + os << p.get_int(); |
| 358 | + return os; |
| 359 | +} |
| 360 | + |
| 361 | +template<> |
| 362 | +struct is_copyable<overaligned_copyable_int> |
| 363 | +{ |
| 364 | + static const bool value = true; |
| 365 | +}; |
| 366 | + |
| 367 | + |
| 368 | + |
290 | 369 | } //namespace test { |
291 | 370 | } //namespace interprocess { |
292 | 371 | } //namespace boost { |
|
0 commit comments