C++ classes for I/O pin abstraction
Allow me to shamelessly plug my open source project https://Kvasir.io . The Kvasir::Io portion provides pin manipulation functions. You must first define your pin using a Kvasir::Io::PinLocation like so:

constexpr PinLocation&lt;0,4&gt; led1;    //port 0 pin 4
constexpr PinLOcation&lt;0,8&gt; led2;


Notice that this does not actually use RAM because these are constexpr variables. 

Throughout your code you can use these pin locations in 'action factory' functions like makeOpenDrain, set, clear, makeOutput and so on. An 'action factory' does not actually execute the action, rather it returns a Kvasir::Register::Action which can be executed using Kvasir::Register::apply(). The reason for this is that apply() merges the actions passed to it when they act on one and the same register so there is an efficiency gain. 

apply(makeOutput(led1),
    makeOutput(led2),
    makeOpenDrain(led1),
    makeOpenDrain(led2));


Since the creation and merging of actions is done at compile time this should yield the same assembler code as the typical hand coded equivalent:

PORT0DIR |= (1&lt;&lt;4) | (1&lt;&lt;8);
PORT0OD |= (1&lt;&lt;4) | (1&lt;&lt;8);