Coder Social home page Coder Social logo

ldionne / libawful Goto Github PK

View Code? Open in Web Editor NEW
108.0 6.0 6.0 16 KB

A collection of awful archetypes to ease the testing of generic C++ libraries

License: Boost Software License 1.0

CMake 15.32% C++ 84.68%
testing cpp cpp11 cpp14 archetype generic-programming

libawful's Introduction

libawful Travis status

A collection of awful archetypes for testing generic code

Overview

When writing a generic library, one often needs to test generic components with types having infrequent characteristics. This is to make sure that a generic component is not assuming more about its inputs than it should. libawful is a collection of types with unusual properties that can be used to check for corner cases when implementing generic components. The project contains a single header, <awful.hpp>, which defines all the archetypes.

#include <awful.hpp>
#include <utility>

template <typename T, typename U>
struct naive_pair {
  T first;
  U second;

  naive_pair() = default;

  template <typename Other, typename = decltype(std::declval<Other>().first),
                            typename = decltype(std::declval<Other>().second)>
  naive_pair(Other&& other)
    : first(std::forward<Other>(other).first),
      second(std::forward<Other>(other).second)
  { }
};

int main() {
  naive_pair<awful::trapconstructible, int> pair;
  auto copy = pair; // ERROR: naive_pair tries to copy-construct its first
                    //        member from a non-const reference to `pair.first`.
}

Compiler requirements

This is a C++14 library, and no effort whatsoever will be made to accommodate nonconforming compilers.

libawful's People

Contributors

ldionne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

libawful's Issues

Awful callable types

Have you considered adding callable types that overload the operator () on combinations of lr-value-ness vs const-ness?

E.g.

struct void_ {};

struct rvalueconstcallable {
    constexpr void_ operator ()(...) const&& {
        return {};
    }
};

This would be useful to check whether generic algorithms forward callable objects correctly up to the point they are invoked.

Tests for self-move

I recently had an issue understanding what is expected from types and standard library algorithms when it comes to self-move and self-swap and arrived at the following conclusion:

  • using std::swap; swap(x, x); is required to leave x unchanged as per the Swappable concept. Therefore standard algorithms are allowed to perform unguarded self-swaps.
  • The standard makes no guarantee concerning x = std::move(x) and from what I gathered around the internet some committee members expect it to leave x in a valid but unspecified state, so standard library algorithms have to avoid performing self-moves if they don't want to accidentally destroy elements (some algorithms expect non-overlapping input and output ranges, so they at least don't have to check for that).

Accordingly I wrote a type which detects self-moves and allows self-swap to try to detect such issues in one of my libraries. Looking at libwaful again, it might also be a suitable type for the library. Here is the current implementation if you're interested, but it currently uses exceptions instead of asserts to report errors, and has some overlap with some of libawful existing types (notably tracked). Nonetheless, I believe that the self-move/self-swap guarantees enforcement might be a valuable addition to the library :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.