Skip to content

A template for declaring function's output parameters

Notifications You must be signed in to change notification settings

akrzemi1/out_param

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

out_param

A template for declaring function's output parameters

Motivation

This small class template out_param can be used to indicate in the function's signature that a given reference parameter is an output parameter:

using namespace ak_toolkit;

void assign(out_param<std::string&> s, // < output parameter
            std::string const& v)
{
    s.get() = v;
}

It does not do any processing. The only benefit of using it is that you cannot pass a reference to a function unless you explicitly wrap it:

std::string s;
assign(out(s), "text");

This forces the function callers to be explicit about passing output arguments to it.

Recommendation

Before using this library for output parameters consider not using output parameters at all, as described in C++ Core Guidelines F.20 and F.21. Only if this is impossible resort to using this library to make the usage of output parameters explicit in the call site.

installation

It is a C++11 single-header (header-only) library.

License

Distributed under the Boost Software License, Version 1.0.

About

A template for declaring function's output parameters

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages