C++ Type Traits for Smart Pointers that are not included in the standard library, containing inheritance detection and member detection.

Overview

Smart Pointer Type Trait ๐ŸŽˆ

A simple, header-only cpp library implementing smart pointer type traits.
You can easily compile your code diffrently depending on which pointer-type is used.
You can detect inheritance too and you won't have trouble with const, volatile qualifiers.
It also contains member detections. (SFINAE based)

Type traits are generally used for static assertions and static polymorphism. (C++ 17 if constexpr)
However, the standard library's type traits do not support smart pointers, and do not detect inheritance.
This is why smart pointer type traits are made.

Release Note

Version 2.0 released.

https://github.com/MyeongWoonJang/cpp-smart-pointer-type-trait/releases/tag/v2.0

If you are looking for old versions, visit here.

Installation

All you need to to is copy over the smart_pointer_type_trait.hpp header file.
Include it in your solution, and you are good to go.

Guide

All evaluations occurs after removing const, volatile, reference.
Implementations are in namespace woon2.

#include "smart_pointer_type_trait.hpp"		// include the header file.

// ...

	woon2::is_smart_ptr_v<T>;		// usage guide 1

	using namespace woon2;			// usage guide 2
	is_smart_ptr_v<T>;

// ...

Hard Type Traits

  • is_pointable
template < typename T >
using is_pointable = detail::is_pointable_impl< detail::remove_cvr_t< T > >;

is_ptr<T>::value/is_ptr_v<T> is true if T has operator* and operator->.
detects all pointable classes such as std::unique_ptr<T>, std::shared_ptr<T>, T*.

  • is_smart_ptr
template < typename T >
using is_smart_ptr = std::conditional_t<
	is_shared_ptr_v< T >,
	std::true_type,
	std::conditional_t<
		is_unique_ptr_v< T >,
		std::true_type,
		std::false_type
		>
	>;

is_smart_ptr<T>::value/is_smart_ptr_v<T> is true if T is std::shared_ptr or std::unique_ptr.

  • is_shared_ptr
template < typename T >
using is_shared_ptr = detail::is_shared_ptr_impl< detail::remove_cvr_t< T > >;

is_shared_ptr<T>::value/is_shared_ptr_v<T> is true if T is std::shared_ptr.

  • is_unique_ptr
template < typename T >
using is_unique_ptr = detail::is_unique_ptr_impl< detail::remove_cvr_t< T > >;

is_unique_ptr<T>::value/is_unique_ptr_v<T> is true if T is std::unique_ptr.

Soft Type Traits

  • is_smart_ptr_soft
template < typename T >
using is_smart_ptr_soft = decltype( detail::is_smart_ptr_soft_impl( std::declval< detail::remove_cvr_t< T >* >() ) );

is_smart_ptr_soft<T>::value/is_smart_ptr_soft_v<T> is true if T is derived from std::shared_ptr or std::unique_ptr.

  • is_shared_ptr_soft
template < typename T >
using is_shared_ptr_soft = decltype( detail::is_shared_ptr_soft_impl( std::declval< detail::remove_cvr_t< T >* >() ) );

is_shared_ptr_soft<T>::value/is_shared_ptr_soft_v<T> is true if T is derived from std::shared_ptr.

  • is_unique_ptr_soft
template < typename T >
using is_unique_ptr_soft = decltype( detail::is_unique_ptr_soft_impl( std::declval< detail::remove_cvr_t< T >* >() ) );

is_unique_ptr_soft<T>::value/is_unique_ptr_soft_v<T> is true if T is derived from std::unique_ptr.

Member Detections

  • has_reset
template < typename T >
using has_reset = detail::has_reset_impl< detail::remove_cvr_t< T > >;	

has_reset<T>::value/has_reset_v<T> is true if T has reset() as a member.

  • has_release
template < typename T >
using has_release = detail::has_release_impl< detail::remove_cvr_t< T > >;	

has_release<T>::value/has_release_v<T> is true if T has release() as a member.

  • has_get_deleter
template < typename T >
using has_get_deleter = detail::has_get_deleter_impl< detail::remove_cvr_t< T > >;	

has_get_deleter<T>::value/has_get_deleter_v<T> is true if T has get_deleter() as a member.

  • has_swap
template < typename T >
using has_swap = detail::has_swap_impl< detail::remove_cvr_t< T > >;	

has_swap<T>::value/has_swap_v<T> is true if T has swap(detail::remove_cvr_t<T>&) as a member.
(detail::remove_cvr_t<T>& is a l-value reference of the pointer.)

Example

Smart Pointer Type Trait1 Smart Pointer Type Trait2

examples of using member detections are on other examples. (example2, example3)

Contributing

we are welcoming your contributions! ๐Ÿ˜Š

Credit

Woon2

Reference

How to write a type trait is container or is vector - stackoverflow

Concept for Smart Pointers - stackoverflow

์”น์–ด๋จน๋Š” C++ - <16 - 3. ํƒ€์ž…์„ ์•Œ๋ ค์ฃผ๋Š” ํ‚ค์›Œ๋“œ decltype ์™€ ์นœ๊ตฌ std::declval> - blog

std::conditional - cppreference

SFINAE - cppreference

Releases(v2.0)
  • v2.0(Dec 22, 2021)

    smart_pointer_type_trait.hpp is the only header file you need to include.

    Example sources are contained. example.cpp is the most intuitive tutorial.

    smart pointer type trait.zip

    Patch Note

    • is_ptr and is_ptr_v have been replaced with is_pointable, which is expanded to all pointable classes and raw pointers.
    • appended a guide for the creation of your own pointer class's type traits in smart_pointer_type_trait.hpp.
      • added an example for it. (example3 - new pointer class type traits.cpp) Following the guide, it implements the creation of new pointer class's type traits.
    • put the features in namespace woon2.
    • more precise implementation for example2 - decoupled pointer.cpp made.
      • testing other pointer type needs modifying no more than one line.
    Source code(tar.gz)
    Source code(zip)
  • release(Dec 21, 2021)

Owner
Woon2
Woon2
C - A repository containing C code samples and concepts for beginners.

C - A repository containing C code samples and concepts for beginners. A repository containing C concepts I made when I was bored. You can also use th

doxxable3 1 Nov 1, 2021
L.A. Noire - V Patch | A community-made patch for the 2011's video game L.A Noire containing a set of fixes like an unlocked framerate or custom aspect ratios.

V-Patch for L.A Noire Complete Edition This project is not affiliated with Take-Two or Rockstar Games A while ago I wanted to replay L.A Noire on my n

null 156 Aug 8, 2022
Trackable ptr - Smart pointer for any movable objects. When trackable object moved/destroyed, trackers updated with new object's pointer.

trackable_ptr Trackable pointer. When trackable object moved/destroyed, trackable_ptrs updated with new object's location. Allow to have stable pointe

null 23 Mar 3, 2022
A demonstration of implementing, and using, a "type safe", extensible, and lazy iterator interface in pure C99.

c-iterators A demonstration of implementing, and using, a "type safe", extensible, and lazy iterator interface in pure C99. The iterable is generic on

Chase 62 Jul 26, 2022
C++ standard library reference

Information This is source package for Cppreference C++ standard library reference documentation available at http://en.cppreference.com. If there is

Povilas Kanapickas 341 Jul 31, 2022
This is a simple UNITEST to test the implementation of the the various container types of the C++ standard template library

ft_container UNITest. This is a simple UNITEST to test the implementation of the the various container types of the C++ standard template library that

Mohamed AMOUSSAOUI 38 Aug 5, 2022
Ideas, thoughts, and notes on a typeclass/interface based polymorphism pattern for standard C

Polymorphism through Typeclasses / Interface / Traits Ideas, thoughts, and notes on an action based polymorphism pattern for good ol' C. Originally us

Chase 23 Jul 29, 2022
The language I did not write

Mercenary After writing so many programming languages myself, I decided that I won't write a single line of code for this language: Instead, I've hire

Sam Westerman 11 Feb 2, 2022
a header-only crossplatform type-safe dynamic compiler generator based on C++ 17.

Mu Compiler Generator MuCompilerGenerator(MuCplGen) a Header-Only dynamic compiler generator based on C++ 17. Why MuCplGen? header-only cross-platform

MuGdxy 11 Dec 31, 2021
This is a C/C++ simulation project which illustrates the framing of standard ethernet protocol

This is a C/C++ simulation project which illustrates the framing of standard ethernet protocol. It creates server and client processes on the same machine and through IPC, it sends the data from the client to the server in a simplex communication.

P Punyacharan 6 Sep 7, 2021
This repository is a summary of the basic knowledge of recruiting job seekers and beginners in the direction of C/C++ technology, including language, program library, data structure, algorithm, system, network, link loading library, interview experience, recruitment, recommendation, etc.

?? C/C++ ๆŠ€ๆœฏ้ข่ฏ•ๅŸบ็ก€็Ÿฅ่ฏ†ๆ€ป็ป“๏ผŒๅŒ…ๆ‹ฌ่ฏญ่จ€ใ€็จ‹ๅบๅบ“ใ€ๆ•ฐๆฎ็ป“ๆž„ใ€็ฎ—ๆณ•ใ€็ณป็ปŸใ€็ฝ‘็ปœใ€้“พๆŽฅ่ฃ…่ฝฝๅบ“็ญ‰็Ÿฅ่ฏ†ๅŠ้ข่ฏ•็ป้ชŒใ€ๆ‹›่˜ใ€ๅ†…ๆŽจ็ญ‰ไฟกๆฏใ€‚This repository is a summary of the basic knowledge of recruiting job seekers and beginners in the direction of C/C++ technology, including language, program library, data structure, algorithm, system, network, link loading library, interview experience, recruitment, recommendation, etc.

huihut 25.2k Aug 7, 2022
Minimal Linux Live (MLL) is a tiny educational Linux distribution, which is designed to be built from scratch by using a collection of automated shell scripts. Minimal Linux Live offers a core environment with just the Linux kernel, GNU C library, and Busybox userland utilities.

Minimal Linux Live (MLL) is a tiny educational Linux distribution, which is designed to be built from scratch by using a collection of automated shell scripts. Minimal Linux Live offers a core environment with just the Linux kernel, GNU C library, and Busybox userland utilities.

John Davidson 1.3k Aug 2, 2022
A cheatsheet of modern C++ language and library features.

C++20/17/14/11 Overview Many of these descriptions and examples come from various resources (see Acknowledgements section), summarized in my own words

Anthony Calandra 14.5k Aug 8, 2022
Feature-rich C99 library for memory scanning purposes, designed for Windows running machines, meant to work on both 32-bit and 64-bit portable executables. Has a modern C++ wrapper.

memscan Feature-rich C99 library for memory scanning purposes, designed for Windows running machines, meant to work on both 32-bit and 64-bit portable

cristei 13 Aug 11, 2022
C++20 Concepts IO library which is 10x faster than stdio and iostream

fast_io fast_io is a new C++20 library for extremely fast input/output and aims to replace iostream and cstdio. It is header-only (module only in the

null 153 Feb 16, 2022
Modern, header-only, compact and cross platform C++ network/sockets library

cpp-net-lib Modern, header-only, compact and cross-platform C++ network/sockets library. Don't mind the crappy name, I suck at naming things. Why? I n

Marc 10 Jul 20, 2022
Connect 4 clone written with c++ with the RSGL library. Based on my connect 4 clone written in python/pygame and my SDL port of that same repo. Along with 3DS support by SaCode

RSGL-Connect-4 Building linux git clone https://github.com/RSGL-Org/RSGL-Connect-4.git cd RSGL-Connect-4 make ./Connect4 Bulding 3ds (3ds support

RSGL 2 Dec 11, 2021
High performance library for creating, modiyfing and parsing PDF files in C++

Welcome to PDF-Writer. A Fast and Free C++ Library for Creating, Parsing an Manipulating PDF Files and Streams. Documentation is available here. Proje

gal kahana 652 Aug 8, 2022
A library of language lexers for use with Scintilla

README for Lexilla library. The Lexilla library contains a set of lexers and folders that provides support for programming, mark-up, and data languag

Scintilla 69 Aug 1, 2022