Skip to content

Commit

Permalink
Fix README.md issues
Browse files Browse the repository at this point in the history
  • Loading branch information
definitelynobody committed Mar 30, 2018
1 parent 859a8c9 commit 0888a8e
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ An header-only alternative to `boost::variant` for C++11 and C++14
## Introduction

Variant's basic building blocks are:

- `variant<Ts...>` - a type-safe representation for sum-types / discriminated unions
- `recursive_wrapper<T>` - a helper type to represent recursive "tree-like" variants
- `apply_visitor(visitor, myVariant)` - to invoke a custom visitor on the variant's underlying type
- `get<T>()` - a function to directly unwrap a variant's underlying type
- `.match([](Type){})` - a variant convenience member function taking an arbitrary number of lambdas creating a visitor behind the scenes and applying it to the variant


### Basic Usage - HTTP API Example

Suppose you want to represent a HTTP API response which is either a JSON result or an error:
Expand Down Expand Up @@ -69,12 +69,10 @@ apply_visitor(visitor, ret);

In both cases the compiler makes sure you handle all types the variant can represent at compile.


### Recursive Variants - JSON Example

[JSON](http://www.json.org/) consists of types `String`, `Number`, `True`, `False`, `Null`, `Array` and `Object`.


```c++
struct String { string value; };
struct Number { double value; };
Expand Down Expand Up @@ -111,7 +109,7 @@ struct Object {
};
```

For walkig the JSON representation you can again either create a `JSONVisitor`:
For walking the JSON representation you can again either create a `JSONVisitor`:

```c++
struct JSONVisitor {
Expand Down Expand Up @@ -146,6 +144,7 @@ struct Node {
uint64_t value;
}
```
### Advanced Usage Tips
Creating type aliases for variants is a great way to reduce repetition.
Expand All @@ -164,7 +163,6 @@ struct APIResult : variant<Error, Result> {
}
```


## Why use Mapbox Variant?

Mapbox variant has the same speedy performance of `boost::variant` but is
Expand All @@ -180,7 +178,6 @@ Time to compile header | 185 ms | 675 ms

(Numbers from an older version of Mapbox variant.)


## Goals

Mapbox `variant` has been a very valuable, lightweight alternative for apps
Expand All @@ -206,53 +203,46 @@ Want to know more about the upcoming standard? Have a look at our
Most modern high-level languages provide ways to express sum types directly.
If you're curious have a look at Haskell's pattern matching or Rust's and Swift's enums.


## Depends

- Compiler supporting `-std=c++11` or `-std=c++14`
- Compiler supporting `-std=c++11` or `-std=c++14`

Tested with:

- g++-4.7
- g++-4.8
- g++-4.9
- g++-5.2
- clang++-3.5
- clang++-3.6
- clang++-3.7
- clang++-3.8
- clang++-3.9
- Visual Studio 2015

- g++-4.7
- g++-4.8
- g++-4.9
- g++-5.2
- clang++-3.5
- clang++-3.6
- clang++-3.7
- clang++-3.8
- clang++-3.9
- Visual Studio 2015

## Unit Tests

On Unix systems compile and run the unit tests with `make test`.

On Windows run `scripts/build-local.bat`.


## Limitations

* The `variant` can not hold references (something like `variant<int&>` is
- The `variant` can not hold references (something like `variant<int&>` is
not possible). You might want to try `std::reference_wrapper` instead.


## Deprecations

* The included implementation of `optional` is deprecated and will be removed
in a future version. See https://github.com/mapbox/variant/issues/64.
* Old versions of the code needed visitors to derive from `static_visitor`.
- The included implementation of `optional` is deprecated and will be removed
in a future version. See [issue #64](https://github.com/mapbox/variant/issues/64).
- Old versions of the code needed visitors to derive from `static_visitor`.
This is not needed any more and marked as deprecated. The `static_visitor`
class will be removed in future versions.


## Benchmarks

make bench


## Check object sizes

make sizes /path/to/boost/variant.hpp

0 comments on commit 0888a8e

Please sign in to comment.