| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #ifndef CERES_PUBLIC_INTERNAL_MEMORY_H_ |
| | #define CERES_PUBLIC_INTERNAL_MEMORY_H_ |
| |
|
| | #include <memory> |
| |
|
| | #ifdef CERES_HAVE_EXCEPTIONS |
| | #define CERES_INTERNAL_TRY try |
| | #define CERES_INTERNAL_CATCH_ANY catch (...) |
| | #define CERES_INTERNAL_RETHROW \ |
| | do { \ |
| | throw; \ |
| | } while (false) |
| | #else |
| | #define CERES_INTERNAL_TRY if (true) |
| | #define CERES_INTERNAL_CATCH_ANY else if (false) |
| | #define CERES_INTERNAL_RETHROW \ |
| | do { \ |
| | } while (false) |
| | #endif |
| |
|
| | namespace ceres { |
| | namespace internal { |
| |
|
| | template <typename Allocator, typename Iterator, typename... Args> |
| | void ConstructRange(Allocator& alloc, |
| | Iterator first, |
| | Iterator last, |
| | const Args&... args) { |
| | for (Iterator cur = first; cur != last; ++cur) { |
| | CERES_INTERNAL_TRY { |
| | std::allocator_traits<Allocator>::construct( |
| | alloc, std::addressof(*cur), args...); |
| | } |
| | CERES_INTERNAL_CATCH_ANY { |
| | while (cur != first) { |
| | --cur; |
| | std::allocator_traits<Allocator>::destroy(alloc, std::addressof(*cur)); |
| | } |
| | CERES_INTERNAL_RETHROW; |
| | } |
| | } |
| | } |
| |
|
| | template <typename Allocator, typename Iterator, typename InputIterator> |
| | void CopyRange(Allocator& alloc, |
| | Iterator destination, |
| | InputIterator first, |
| | InputIterator last) { |
| | for (Iterator cur = destination; first != last; |
| | static_cast<void>(++cur), static_cast<void>(++first)) { |
| | CERES_INTERNAL_TRY { |
| | std::allocator_traits<Allocator>::construct( |
| | alloc, std::addressof(*cur), *first); |
| | } |
| | CERES_INTERNAL_CATCH_ANY { |
| | while (cur != destination) { |
| | --cur; |
| | std::allocator_traits<Allocator>::destroy(alloc, std::addressof(*cur)); |
| | } |
| | CERES_INTERNAL_RETHROW; |
| | } |
| | } |
| | } |
| |
|
| | } |
| | } |
| |
|
| | #endif |
| |
|