0

I am intending to use classes that have boost::multiprecision::cpp_int (see Boost Multiprecision) as data members, and I am hoping to manage instances of these classes on the heap using the boost::fast_pool_allocator Boost custom allocator.

In order for this to be safe, I need to know that boost::multiprecision::cpp_int is a POD (or at least that it does no allocation on the heap - i.e., is purely stack-based).

Is boost::multiprecision::cpp_int a POD?

Thanks!

Dan Nissenbaum
  • 13,558
  • 21
  • 105
  • 181
  • 2
    Think about it for a moment, where could it possibly extend into when it grows? Also what could maybe "Determines the number of Bits to store directly within the object before resorting to dynamic memory allocation" in the documentation you have linked mean? – PlasmaHH Apr 09 '14 at 08:00
  • 1
    Yes - this is an obvious point now for me, thanks. – Dan Nissenbaum Apr 09 '14 at 08:47

2 Answers2

4

Why not write a little program to find out?

#include <iostream>
#include <type_traits>
#include <boost/multiprecision/cpp_int.hpp>

int main()
{
    std::cout << std::is_pod<boost::multiprecision::cpp_int>::value << std::endl;
}

On my platform (gcc version 4.8.2) the output is 0, meaning the type isn't a POD type.

bstamour
  • 7,746
  • 1
  • 26
  • 39
  • Is there a type traits class that will indicate if it allocates on the heap? I think my POD restriction may be too restrictive. I just need to know that it's fully stack-based. – Dan Nissenbaum Apr 08 '14 at 15:17
  • Here's a list of the type traits that is included in C++: http://en.cppreference.com/w/cpp/header/type_traits – bstamour Apr 08 '14 at 15:18
2

The answer, taken from @PlasmaHH's comment, and quite obvious in retrospect, is that no, boost::multiprecision::cpp_int is not a POD.

To quote from PlasmaHH:

Think about it for a moment, where could it possibly extend into when it grows? Also what could maybe "Determines the number of Bits to store directly within the object before resorting to dynamic memory allocation" in the documentation you have linked mean?

Dan Nissenbaum
  • 13,558
  • 21
  • 105
  • 181