Reproduce special members table

Flaviu_ 1,011 Reputation points
2024-10-04T09:28:50+00:00

I have the following (well known) table:

User's image

Can I test it by using type_traits?

I wrote:

class CSpecialMethods
{
public:
//	CSpecialMethods() {}
// 	CSpecialMethods(bool) {}
//	CSpecialMethods(const CSpecialMethods& rhs) {}
	CSpecialMethods& operator=(const CSpecialMethods& rhs) {} // declare user copy assignment operator, nothing else
//	CSpecialMethods(CSpecialMethods&& rhs) {}
//	CSpecialMethods& operator=(CSpecialMethods&& rhs) {}
//	~CSpecialMethods() {}
};

and

	std::clog << "constructors:" << std::endl;
	std::clog << std::is_trivially_default_constructible_v<CSpecialMethods> << std::endl;
	std::clog << std::is_trivially_constructible_v<CSpecialMethods> << std::endl;
	std::clog << "copy methods:" << std::endl;
	std::clog << std::is_trivially_copy_constructible_v<CSpecialMethods> << std::endl;
	std::clog << std::is_trivially_copy_assignable_v<CSpecialMethods> << std::endl;
	std::clog << "move methods:" << std::endl;
	std::clog << std::is_trivially_move_constructible_v<CSpecialMethods> << std::endl;
	std::clog << std::is_trivially_move_assignable_v<CSpecialMethods> << std::endl;
	std::clog << "destructor:" << std::endl;
	std::clog << std::is_trivially_destructible_v<CSpecialMethods> << std::endl;

but the outcome does not reflect the table:

constructors:

1

1

copy methods:

1

0

move methods:

1

0

destructor:

1

So, can I reproduce that special members table using type_traits?

If I write:

class CSpecialMethods
{
public:
//	CSpecialMethods() {}
// 	CSpecialMethods(bool) {}
	CSpecialMethods(const CSpecialMethods& rhs) = default;
	CSpecialMethods& operator=(const CSpecialMethods& rhs) {}
//	CSpecialMethods(CSpecialMethods&& rhs) {}
//	CSpecialMethods& operator=(CSpecialMethods&& rhs) {}
//	~CSpecialMethods() {}
};

I got:

constructors:

0

0

copy methods:

1

0

move methods:

1

0

destructor:

1

Quite different then other sample, but still, doesn't reflect the top table ...

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,758 questions
0 comments No comments
{count} votes

Accepted answer
  1. Minxin Yu 12,001 Reputation points Microsoft Vendor
    2024-10-04T13:15:03.4333333+00:00

    Hi,

    After my test,

    ~CSpecialMethods() {} or =default are different results.

    In addition, from the doc:

    the class Ty has no virtual functions

    So type_traits is not reliable.

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.