All Projects → martinmoene → Observer Ptr Lite

martinmoene / Observer Ptr Lite

Licence: bsl-1.0
observer-ptr - An observer_ptr for C++98 and later in a single-file header-only library (Extensions for Library Fundamentals, v2, v3)

Programming Languages

cpp17
186 projects

Projects that are alternatives of or similar to Observer Ptr Lite

Litepicker
Date range picker - lightweight, no dependencies
Stars: ✭ 442 (+1200%)
Mutual labels:  no-dependencies
Gumshoe
A simple vanilla JS scrollspy script.
Stars: ✭ 640 (+1782.35%)
Mutual labels:  no-dependencies
Hed
vim like hex editor
Stars: ✭ 23 (-32.35%)
Mutual labels:  no-dependencies
Atomic
A tiny, Promise-based vanilla JS Ajax/HTTP plugin with great browser support.
Stars: ✭ 526 (+1447.06%)
Mutual labels:  no-dependencies
Rmodal.js
A simple 1.2 KB modal dialog with no dependencies
Stars: ✭ 613 (+1702.94%)
Mutual labels:  no-dependencies
Units
a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
Stars: ✭ 653 (+1820.59%)
Mutual labels:  no-dependencies
Tacopie
C++ TCP Library - NO LONGER MAINTAINED
Stars: ✭ 359 (+955.88%)
Mutual labels:  no-dependencies
Humblelogging
HumbleLogging is a lightweight C++ logging framework. It aims to be extendible, easy to understand and as fast as possible.
Stars: ✭ 15 (-55.88%)
Mutual labels:  no-dependencies
Gsl Lite
gsl-lite – A single-file header-only version of ISO C++ Guidelines Support Library (GSL) for C++98, C++11, and later
Stars: ✭ 617 (+1714.71%)
Mutual labels:  no-dependencies
Simplog
A simple logger. No dependencies, no special features, just logging.
Stars: ✭ 17 (-50%)
Mutual labels:  no-dependencies
Entt
Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more
Stars: ✭ 6,017 (+17597.06%)
Mutual labels:  no-dependencies
Rucaptcha
Captcha gem for Rails Application. No dependencies. No ImageMagick, No RMagick.
Stars: ✭ 607 (+1685.29%)
Mutual labels:  no-dependencies
Robin Hood Hashing
Fast & memory efficient hashtable based on robin hood hashing for C++11/14/17/20
Stars: ✭ 658 (+1835.29%)
Mutual labels:  no-dependencies
Tabby
Lightweight, accessible vanilla JS toggle tabs.
Stars: ✭ 449 (+1220.59%)
Mutual labels:  no-dependencies
Metro Ui Css
Impressive component library for expressive web development! Build responsive projects on the web with the first front-end component library in Metro Style. And now there are even more opportunities every day!
Stars: ✭ 6,843 (+20026.47%)
Mutual labels:  no-dependencies
Tomlplusplus
Header-only TOML config file parser and serializer for C++17 (and later!).
Stars: ✭ 403 (+1085.29%)
Mutual labels:  no-dependencies
Vuebar
(🗃️ Archived) Vue 2 directive for custom scrollbar that uses native scroll behavior. Lightweight, performant, customizable and without dependencies. Used successfully in production on https://ggather.com
Stars: ✭ 650 (+1811.76%)
Mutual labels:  no-dependencies
Vanilla Emoji Picker
Modern emoji picker. Super light 2kb gzipped, simple and no frameworks 😻
Stars: ✭ 20 (-41.18%)
Mutual labels:  no-dependencies
Cpp redis
C++11 Lightweight Redis client: async, thread-safe, no dependency, pipelining, multi-platform - NO LONGER MAINTAINED - Please check https://github.com/cpp-redis/cpp_redis
Stars: ✭ 855 (+2414.71%)
Mutual labels:  no-dependencies
Byob
An open-source post-exploitation framework for students, researchers and developers.
Stars: ✭ 6,949 (+20338.24%)
Mutual labels:  no-dependencies

observer_ptr<> for C++98 up

Language License Build Status Build status Version download Conan Try it online Try it on godbolt online

observer-ptr is a single-file header-only library with a variant of std::experimental::observer_ptr [1] for C++98 and later.

Contents

Example usage

#include "nonstd/observer_ptr.hpp"

using namespace nonstd;

void use( observer_ptr<int> p )
{
    assert( *p == 42 );
}

int main()
{
    int a = 42;
    observer_ptr<int> p( &a );
    use( p );
}

Compile and run

prompt>g++ -std=c++03 -Wall -I../include -o 01-basic.exe 01-basic.cpp && 01-basic.exe

In a nutshell

observer-ptr is an implementation of the world’s dumbest smart pointer for C++98 and higher. It takes no ownership responsibility for the object it observes or watches and is intended as a near drop-in replacement for raw pointer types. As a vocabulary type it indicates intended use, easing code reading (Note 1).

Class template observer_ptr<> has been proposed for inclusion into the C++ standard [1] and is part of Extensions for Library Fundamentals v2/v3 [2][3].

The observer-ptr of this project can be used with probably any clang, g++ or MSVC compiler. It has been tested with clang 3.4, g++ 5.2 and with VC6 (VS6, no comparison of observers), VC8 (VS2005), VC10 (VS2010), VC11 (VS2012), VC12 (VS2013), VC14 (VS2015).

License

observer-ptr is distributed under the Boost Software License.

Dependencies

observer-ptr has no other dependencies than the C++ standard library.

Installation

observer-ptr is a single-file header-only library. Put observer_ptr.h in the include folder directly into the project source tree or somewhere reachable from your project.

Building the tests

To build the tests you need:

The lest test framework is included in the test folder.

The following steps assume that the observer-ptr source code has been cloned into a directory named c:\observer-ptr.

  1. Create a directory for the build outputs for a particular architecture.
    Here we use c:\observer-ptr\build-win-x86-vc10.

     cd c:\observer-ptr
     md build-win-x86-vc10
     cd build-win-x86-vc10
    
  2. Configure CMake to use the compiler of your choice (run cmake --help for a list).

     cmake -G "Visual Studio 10 2010" ..
    
  3. Build the test suite in the Debug configuration (alternatively use Release).

     cmake --build . --config Debug
    
  4. Run the test suite.

     ctest -V -C Debug
    

All tests should pass, indicating your platform is supported and you are ready to use observer-ptr.

Synopsis

Contents
Documentation of std::experimental::observer_ptr
Configuration macros

Documentation of std::experimental::observer_ptr

Depending on the compiler and C++-standard used, nonstd::observer_ptr behaves less or more like std::experimental::observer_ptr. To get an idea of the capabilities of nonstd::observer_ptr with your configuration, look at the output of the tests, issuing observer_ptr-main.t --pass @. For std::experimental::observer_ptr, see its documentation at cppreference [5].

Configuration macros

Standard selection macro

-Dnsop_CPLUSPLUS=199711L
Define this macro to override the auto-detection of the supported C++ standard, or if your compiler does not set the __cplusplus macro correctly.

Select std::experimental::observer_ptr or nonstd::observer_ptr

At default, observer-ptr lite uses std::experimental::observer_ptr if it is available and lets you use it via namespace nonstd. You can however override this default and explicitly request to use std::experimental::observer_ptr or observer-ptr lite's nonstd::observer_ptr as nonstd::observer_ptr via the following macros.

-Dnsop_CONFIG_SELECT_OBSERVER_PTR=nsop_OBSERVER_PTR_DEFAULT
Define this to nsop_OBSERVER_PTR_STD to select std::experimental::observer_ptr as nonstd::observer_ptr. Define this to nsop_OBSERVER_PTR_NONSTD to select nonstd::observer_ptr as nonstd::observer_ptr. Default is undefined, which has the same effect as defining to nsop_OBSERVER_PTR_DEFAULT.

Conversions

-Dnsop_CONFIG_ALLOW_IMPLICIT_CONVERSION_FROM_SMART_PTR=0
Allow implicit conversion from std::unique_ptr and std::shared_ptr. This is an extension to the proposal. Each of these implicit conversions can also be activated separately, see below. Default is 0.

-Dnsop_CONFIG_ALLOW_IMPLICIT_CONVERSION_FROM_UNIQUE_PTR=0
Allow implicit conversion from std::unique_ptr. This is an extension to the proposal. Default is 0.

-Dnsop_CONFIG_ALLOW_IMPLICIT_CONVERSION_FROM_SHARED_PTR=0
Allow implicit conversion from std::shared_ptr. This is an extension to the proposal. Default is 0.

-Dnsop_CONFIG_ALLOW_IMPLICIT_CONVERSION_TO_UNDERLYING_TYPE=0
The proposed observer_ptr provides explicit conversions to bool and to the underlying type. Explicit conversion is not available from pre-C++11 compilers. To prevent problems due to unexpected implicit conversions to bool or to the underlying type, this library does not provide these implicit conversions at default. If you still want them, define this macro to 1. Without these implicit conversions enabled, a conversion to bool via the safe bool idiom is provided. Default is 0.

Compile-time tests

-Dnsop_CONFIG_CONFIRMS_COMPILATION_ERRORS=0
Define this macro to 1 to experience the by-design compile-time errors of the observer-ptr components in the test suite. Default is 0.

Other open source implementations

Notes and references

Notes

Note 1. This conclusion may be challenged if the coding style ensures that any raw pointer is a non-owning pointer [4].

References

[1] Walter E. Brown. N3840: A Proposal for the World’s Dumbest Smart Pointer, v4 (v1, v2, v3, v4 (PDF). 19 December 2012 - 7 November 2014.
[2] N4481: Tentative Working Draft, C++ Extensions for Library Fundamentals, Version 2, Section 4.2 Non-owning pointers. 12 April 2015.
[3] N4758: Working Draft, C++ Extensions for Library Fundamentals, Version 3, Section 5.2 Non-owning pointers. 13 November 2018.
[4] Bjarne Stroustrup. P1408: Abandon observer_ptr. 4 January 2018.
[5] ISO C++ Standard - Future Proposals. shared_ptr and unique_ptr should both implicitly convert to observer_ptr. 24 October 2018.
[6] Joseph Thomson. Pointers and the C++ Core Guidelines. 9 February 2017.
[7] C++ Core Guidelines. Issue 847: Pointers and the C++ Core Guidelines. 9 February 2017.
[8] Boost developers' mailing list. Is there any interest in non-owning pointer-like types? 1 February 2017.
[9] cppreference.com. std::experimental::observer_ptr.

Appendix

A.1 Compile-time information

The version of observer-ptr lite is available via tag [.version]. The following tags are available for information on the compiler and on the C++ standard library used: [.compiler], [.stdc++], [.stdlanguage] and [.stdlibrary].

A.2 Observer Ptr test specification

Disallows to delete the observer_ptr unless implicit conversion allowed
Disallows construction from an observer_ptr of incompatible type
Disallows implicit conversion to bool unless implicit conversion allowed
Disallows implicit conversion to underlying type unless implicit conversion allowed
Disallows comparison to an observer_ptr with a different underlying type
Allows default construction
Allows construction from nullptr
Allows construction from a non-null pointer
Allows construction from an observer_ptr of compatible type
Allows implicit move-construction from a std::unique_ptr<> [smart-ptr][extension]
Allows implicit construction from a std::shared_ptr<> [smart-ptr][extension]
Allows to retrieve the pointer
Allows to retrieve the value pointed to
Allows to retrieve the member pointed to
Allows to test for a non-null pointer via conversion to bool
Allows to convert to the observed pointer [underlying-type][extension]
Allows to release to stop observing
Allows to reset to stop observing
Allows to reset to observe another pointer
Allows to swap two observers
Specialized: Allows to swap two observers
Specialized: Allows to make an observer
Specialized: Allows to compare if an observer is equal to another observer
Specialized: Allows to compare if an observer is equal to another observer with a related watched type
Specialized: Allows to compare if an observer is not equal to another observer
Specialized: Allows to compare if an observer is not equal to another observer with a related watched type
Specialized: Allows to compare if an observer is equal to nullptr
Specialized: Allows to compare if an observer is not equal to nullptr
Specialized: Allows to compare if an observer is less than another observer
Specialized: Allows to compare if an observer is less than another observer with a related watched type
Specialized: Allows to compare if an observer is less than or equal to another observer
Specialized: Allows to compare if an observer is less than or equal to another observer with a related watched type
Specialized: Allows to compare if an observer is greater than another observer
Specialized: Allows to compare if an observer is greater than another observer with a related watched type
Specialized: Allows to compare if an observer is greater than or equal to another observer
Specialized: Allows to compare if an observer is greater than or equal to another observer with a related watched type
Specialized: Allows to compute hash
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].