Giter Club home page Giter Club logo

iod's Introduction

Travis build status

Important Note

This project has been refactored and renamed as the Lithium Libraries: https://github.com/matt-42/lithium

The IOD Library

The IOD library enhances C++14 meta programming with a symbol based paradigm. It provides a compile-time way to introspect objects and generate code matching their data structures. It also contains few utilities built with symbol meta-programming.

What is a IOD symbol?

Symbols are at the core of the IOD paradigm. They add to C++ a missing powerful feature: The way to statically store in a variable the access to an object member, the call to a method, and the access to the string representing the name of this variable. Here is the most simple but powerful operator that is now possible with IOD symbols:

#include <iostream>
#include <iod/symbol.hh>

iod_define_symbol(a); // Refer to members and methods a with symbol _a
iod_define_symbol(b); // Refer to members and methods b with symbol _b
iod_define_symbol(c); // Refer to members and methods c with symbol _c

int main() {

  // Symbols are located in namespace s to avoid name clash.
  using s;

  auto print_member = [] (auto& obj, auto& m)
                      {
                        std::cout << "obj." << m.name()
                                  << " == " << m.member_access(obj) << std::endl;
                      };

  struct { int a; int b; int c; } obj{21, 42, 84};
  print_member(obj, _a); // Prints "obj.a == 21"
  print_member(obj, _b); // Prints "obj.b == 42"
  print_member(obj, _c); // Prints "obj.c == 84"
}

Without symbols (or other similar constructs), it is not possible to write such a generic print_member function. Without, one would have to write the three version accessing the three different members.

By convention all the symbols start with the _[lowercase character]. And to avoid multiple definitions, guards should be used such as in the following:

#ifndef IOD_SYMBOL_mysymbol
#define IOD_SYMBOL_mysymbol
  iod_define_symbol(mysymbol);
#endif
}

The script tools/generate_symbol_definitions.sh automates this process by converting a file containing a list of symbols into a valid C++ header containing the symbol definitions.

Statically introspectable objects (SIO)

Statically introspectable objects features are:

  • The ability to instantiate C++ objects without having to declare any struct or class.
  • Zero cost static introspection (i.e. without overhead on execution time or memory) on those objects.
  // Define an object
  auto o = D(_name = "John", _age = 42, _city = "NYC");
  // Direct access to its members.
  assert(o.name == "John" && o.age == 42 && o.city == "NYC");

  // Static Introspection. It has no execution cost since these function
  // are computed at compile time.
  assert(o.has(_name) == true);
  assert(o.has(_firstName) == false);
  assert(o.has(_firstName) == false);
  assert(o.size() == 3);

  // Output the structure of the object to std::cout:
  // name:John
  // age:42
  // city:NYC
  foreach(o) | [] (auto& m) { std::cout << m.symbol().name() << ":"
                                        << m.value() << std::end; }

Command line parser.

Iod provides an easy to use, type safe command line parser :

const char* argv[] = {"", "--opt1" , "12", "--opt2", "abc"};
int argc = 5;
auto opts = parse_command_line(argc, argv,
                               _opt1 = int(),
                               _opt2 = std::string());
// With
// ./a.out --opt1 12 --opt2 abc
// It should give
// opts.opt1 == 12
// opts.opt2 == "abc"

More example can be found in the test here: https://github.com/matt-42/iod/blob/master/tests/parse_command_line.cc

A Fast, Malloc-Free Json Parser / Encoder.

As of today, all json parsers rely upon dynamic data structures to parse and store the json objects. Even if some good parser reduces dramatically the amount of dynamic memory allocation, they still suffer from the dynamic paradigm: A single function has to handle the whole set of possible json objects. This comes to the absurd situation where a program handling a small set specific json object types have to use a json parser handling any kind of objects.

The iod library implements the opposite approach: Using meta-programming and introspection, one tiny specialized json parser is generated for each SIO object type so it involves no dynamic memory allocation and very few conditional branching. It directly fills the object member according to their type without having to store the object in an intermediate hash map.

This makes its performances impossible to match in other languages such as C or Java that do not provide static introspection. The encoder still needs optimizations, and the parser is currently from 1.3x to 2.3x faster than the RapidJSON library without explicit use of SIMD vector instructions.

The only limitation of this design is when using a very large type set of json objects, the total code size of the generated parsers will be bigger than a generic dynamic parser.

Note on memory allocation: While the parser does not allocate any intermediate structure, it allocates the destination object's members if they are of type std::vector or std::string.

// The type of the object contains attributes related to its json
// representation such as alternative json keys and whether or not a
// field should not be included in the json representation.
typedef decltype(D(_name(_json_key = _username) = std::string(),
                   _age(_json_skip) = int(),
                   _city = std::string())) User;
  
User u("John", 23, "NYC");

// Encode to a json string.
auto str = json_encode(u);
assert(str == R"({"username":"John","city":"NYC"})");

// Decode a json string representing a user.
User u2; json_decode(u2, str);
assert(u2.name == "John" and u2.city == "NYC");

// The json throw exceptions when some value type mismatch
// the object or when some fields are missing:

json_decode(u2, R"({"username":"John"})");
// Exception: json_decode error: missing field city.

json_decode(u2, R"({"username":"John","city":22})");
//  Exception:
//  Json parse error near name":"John","city":22
                                             ^^^
//  Expected " got 2

Named Optional Function Arguments

In classic C++, you would define a function taking optional arguments as :

void fun(int mandatory_arg, int optional_arg1 = 1, int optional_arg2 = 12, int optional_arg3 = 32);

This has two drawbacks: First, it is not practical if the user needs to set the third optional argument, and oblige him to remember the place of each argument. SIOs are a good alternative since they solve both issues:

template <typename... O>
void fun(int mandatory_arg, const O&... opts)
{
  const auto options = D(opts...);
  int optional_arg1 = options.get(_optional_arg1, 1); // return options.optional_arg1 or 1 if not set.
  int optional_arg2 = options.get(_optional_arg2, 12);
  int optional_arg3 = options.get(_optional_arg3, 32);
}

fun(1, _optional_arg3 = 2); // Set the thirds argument and leave the two others to their default value.

Foreach for tuple and SIO

While C++11 introduce range based for loops for a container such as std::vector, it does not provide a way to iterate on tuples. foreach is a powerful primitive for processing tuples as well as SIOs.

auto my_tuple = std::make_tuple(1, "test", 34.f);
// Prints 1 test 34.f.
foreach(my_tuple) | [] (auto& e) { std::cout << e << " "; }

auto my_sio = D(_name = "John", _age = 42);
// Prints name John age 42
foreach(my_sio) | [] (auto& m) { std::cout << m.symbol().name() << " " << m.value() << " "; }

foreach also allows to iterate on several object of the same length (but different types):

auto t1 = std::make_tuple(1, "test", 34.f);
auto t2 = std::make_tuple("x", 34.f, "y");
// Prints 1 xxx test 34 34 y
foreach(t1, t2) | [] (auto& a, auto& b) { std::cout << a << " " << b << " "; }

Furthermore, it automatically builds a new tuple if the given function returns a non void value:

auto t1 = std::make_tuple(1, "A", 34.f);
auto t2 = std::make_tuple(2, "B", 2);
auto t3 = foreach(t1, t2) | [] (auto& a, auto& b) { return a + b; };
// t3 == <3, "AB", 36>

Apply tuples and SIOs to functions

The apply primitive map elements of a tuple or SIO to a given function.

int fun(int x, float y) { return x + y; }

auto tuple = std::make_tuple(1, 2.f);
int res = apply(tuple, fun);
// res == 3

C++ Embedded Domain Specific Languages Framework

The IOD library provides a set of tools to ease the embedding of an embedded domain specific languages (EDSL) framework. It includes an abstract syntax tree (AST) with symbols and values as terminals. Here is an example of a simple expression:

auto exp = _a(23) + _b;

This code does nothing except computing the AST type and storing the value 23. exp has to be evaluated to actually compute something. IOD provides three handy primitives to traverse ASTs: exp_map_reduce, exp_transform, exp_tranform_iterate. More documentation will come later. In the meantime, you can check how the Video++ library implements its image processing C++ EDSL: https://github.com/matt-42/vpp/blob/master/vpp/core/liie.hh

Language Integrated Queries

To demonstrate the power of the IOD framework, we embedded an implementation of a subset of the SQL language in the C++ language. It handles SELECT, FROM, WHERE, INNER_JOIN (with the ON criteria), ORDER BY, GROUP BY, and aggregates such as average or sum.

Given two collection:

std::vector<decltype(D(_name = std::string(), _age() = int(), _city_id = int()))> persons;
std::vector<decltype(D(_id = int(), _name() = std::string(), _zipcode = int()))> cities;

The following requests are valid:

// SELECT * from persons;
linq.select().from(persons) | [] (auto& p) { std::cout << p.name << std::endl; }
// SELECT myname = name from persons WHERE age > 42;
linq.select(_myname = _name).from(persons).where(_age > 42) |
  [] (auto& p) { std::cout << p.myname << std::endl; }
// SELECT name = person.name, city = city.name
//        FROM persons as person
//        INNER JOIN cities as city
//        ON person.city_id == city.id
linq.select(_name = _person[_name], _city = _city[_name])
    .from(persons, _as(_person))
    .inner_join(cities, _as(_city),
              _on(_city[_cp] == _person[_cp])) |
  [] (auto& p) { std::cout << p.name << " lives in " << p.city << std::endl; }
// SELECT age = avg(age), city_id = city_id
//        FROM persons
//        GROUP BY city_id

linq.select(_age = _avg(_age), _city_id = _city_id)
    .from(persons)
    .group_by(_city_id) |
  [] (auto& p) { std::cout << p.age << " is the average age in city " << p.city_id << std::endl; }

Compilers support

IOD relies on the C++14 standard. It has been successfully compiled with :

  • GCC 4.9
  • Clang 3.4

Contributing

Contributions or suggestions are welcome. Do not hesitate to fill issues, send pull requests, or discuss by email at [email protected].

iod's People

Contributors

cybrilla-rajaravivarma avatar duckie avatar fish2000 avatar kazuo256 avatar matt-42 avatar olivier-detour avatar tusharpm 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  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

iod's Issues

json_encode doesn't escape quotes

json_string s{"""};
json_encode( s ); // got unescaped "

Actually noted in Silicon: json_encode'ing some D object with string containing quotes returns invalid JSON.

"iod_define_attribute" in global namespace

Now, all iod_define_attribute objects in global namespace:
namespace { NAME##_attribute_name<0> NAME; }

So compiler throw error if I make my own class with the same name.

I don't know is it possible, but it would be nice to move them to some namespace.

Error during building on Debian 8 (within silicon building)

cat /etc/issue
Debian GNU/Linux 8 \n \l

Trying to install silicon on my linux server machine.

git clone https://github.com/matt-42/silicon.git
mkdir silicon_build
cd silicon
./install.sh ../silicon_build/

Output:

-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is Clang 3.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /root/silicon/silicon_build
Install the project...
-- Install configuration: ""
-- Installing: /root/silicon_build/include/silicon
-- Installing: /root/silicon_build/include/silicon/remote_api.hh
-- Installing: /root/silicon_build/include/silicon/backends
-- Installing: /root/silicon_build/include/silicon/backends/rabbitmq.hh
-- Installing: /root/silicon_build/include/silicon/backends/ws_route.hh
-- Installing: /root/silicon_build/include/silicon/backends/wspp_connection.hh
-- Installing: /root/silicon_build/include/silicon/backends/mimosa.hh
-- Installing: /root/silicon_build/include/silicon/backends/ws_api.hh
-- Installing: /root/silicon_build/include/silicon/backends/mhd.hh
-- Installing: /root/silicon_build/include/silicon/backends/cppnet.hh
-- Installing: /root/silicon_build/include/silicon/backends/h2o.hh
-- Installing: /root/silicon_build/include/silicon/backends/websocketpp.hh
-- Installing: /root/silicon_build/include/silicon/backends/websocketpp_remote_client.hh
-- Installing: /root/silicon_build/include/silicon/backends/urldecode.hh
-- Installing: /root/silicon_build/include/silicon/backends/lwan.hh
-- Installing: /root/silicon_build/include/silicon/middlewares
-- Installing: /root/silicon_build/include/silicon/middlewares/mysql_session.hh
-- Installing: /root/silicon_build/include/silicon/middlewares/mysql_orm.hh
-- Installing: /root/silicon_build/include/silicon/middlewares/mysql_connection.hh
-- Installing: /root/silicon_build/include/silicon/middlewares/sqlite_orm.hh
-- Installing: /root/silicon_build/include/silicon/middlewares/sqlite_types.hh
-- Installing: /root/silicon_build/include/silicon/middlewares/mysql_types.hh
-- Installing: /root/silicon_build/include/silicon/middlewares/tracking_cookie.hh
-- Installing: /root/silicon_build/include/silicon/middlewares/sqlite_connection.hh
-- Installing: /root/silicon_build/include/silicon/middlewares/sqlite_session.hh
-- Installing: /root/silicon_build/include/silicon/middlewares/sql_orm.hh
-- Installing: /root/silicon_build/include/silicon/middlewares/sql_session.hh
-- Installing: /root/silicon_build/include/silicon/middlewares/hashmap_session.hh
-- Installing: /root/silicon_build/include/silicon/middlewares/get_parameters.hh
-- Installing: /root/silicon_build/include/silicon/base_64.hh
-- Installing: /root/silicon_build/include/silicon/sql_rest.hh
-- Installing: /root/silicon_build/include/silicon/utils.hh
-- Installing: /root/silicon_build/include/silicon/blob.hh
-- Installing: /root/silicon_build/include/silicon/hash.hh
-- Installing: /root/silicon_build/include/silicon/clients
-- Installing: /root/silicon_build/include/silicon/clients/templates
-- Installing: /root/silicon_build/include/silicon/clients/templates/javascript_websocket.hh
-- Installing: /root/silicon_build/include/silicon/clients/templates/javascript.hh
-- Installing: /root/silicon_build/include/silicon/clients/javascript_client.hh
-- Installing: /root/silicon_build/include/silicon/clients/libcurl_client.hh
-- Installing: /root/silicon_build/include/silicon/response.hh
-- Installing: /root/silicon_build/include/silicon/procedure_desc.hh
-- Installing: /root/silicon_build/include/silicon/middleware_factories.hh
-- Installing: /root/silicon_build/include/silicon/dynamic_routing_table.hh
-- Installing: /root/silicon_build/include/silicon/api_to_sio.hh
-- Installing: /root/silicon_build/include/silicon/api_description.hh
-- Installing: /root/silicon_build/include/silicon/sql_crud.hh
-- Installing: /root/silicon_build/include/silicon/error.hh
-- Installing: /root/silicon_build/include/silicon/api.hh
-- Installing: /root/silicon_build/include/silicon/http_route.hh
-- Installing: /root/silicon_build/include/silicon/service.hh
-- Installing: /root/silicon_build/include/silicon/di_factories.hh
-- Installing: /root/silicon_build/include/silicon/symbols.hh
-- Installing: /root/silicon_build/include/silicon/file.hh
-- Installing: /root/silicon_build/include/silicon/optional.hh
-- Installing: /root/silicon_build/include/silicon/rmq_route.hh
-- Installing: /root/silicon_build/include/silicon/null.hh
-- Installing: /root/silicon_build/include/silicon
-- Installing: /root/silicon_build/include/silicon/backends
-- Installing: /root/silicon_build/include/silicon/middlewares
-- Installing: /root/silicon_build/include/silicon/clients
-- Installing: /root/silicon_build/include/silicon/clients/templates
Cloning into 'iod'...
remote: Counting objects: 1113, done.
remote: Total 1113 (delta 0), reused 0 (delta 0), pack-reused 1113
Receiving objects: 100% (1113/1113), 360.44 KiB | 0 bytes/s, done.
Resolving deltas: 100% (755/755), done.
Checking connectivity... done.
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is Clang 3.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Boost version: 1.55.0
-- Configuring done
-- Generating done
-- Build files have been written to: /root/silicon/silicon_build/externals/iod/silicon_build
Scanning dependencies of target iod_generate_symbols
Scanning dependencies of target apply
Scanning dependencies of target array_view
Scanning dependencies of target aos_view
[  6%] [ 12%] Building CXX object tools/CMakeFiles/iod_generate_symbols.dir/iod_generate_symbols.cc.o
[ 18%] [ 25%] Building CXX object tests/CMakeFiles/aos_view.dir/aos_view.cc.o
Building CXX object tests/CMakeFiles/apply.dir/apply.cc.o
Building CXX object tests/CMakeFiles/array_view.dir/array_view.cc.o
Linking CXX executable apply
Linking CXX executable array_view
[ 25%] Built target apply
Scanning dependencies of target bind_method
[ 25%] Built target array_view
[ 31%] Building CXX object tests/CMakeFiles/bind_method.dir/bind_method.cc.o
Scanning dependencies of target callable_traits
[ 37%] Building CXX object tests/CMakeFiles/callable_traits.dir/callable_traits.cc.o
Linking CXX executable aos_view
[ 37%] Built target aos_view
Scanning dependencies of target core
[ 43%] Building CXX object tests/CMakeFiles/core.dir/core.cc.o
Linking CXX executable callable_traits
Linking CXX executable bind_method
[ 43%] Built target callable_traits
Scanning dependencies of target deep_merge
[ 43%] [ 50%] Built target bind_method
Building CXX object tests/CMakeFiles/deep_merge.dir/deep_merge.cc.o
Scanning dependencies of target di
[ 56%] Building CXX object tests/CMakeFiles/di.dir/di.cc.o
Linking CXX executable core
[ 56%] Built target core
Scanning dependencies of target foreach
[ 62%] Building CXX object tests/CMakeFiles/foreach.dir/foreach.cc.o
Linking CXX executable iod_generate_symbols
Linking CXX executable di
[ 62%] Built target di
Scanning dependencies of target json
[ 62%] [ 68%] Built target iod_generate_symbols
Building CXX object tests/CMakeFiles/json.dir/json.cc.o
Scanning dependencies of target options
[ 75%] Building CXX object tests/CMakeFiles/options.dir/options.cc.o
Linking CXX executable foreach
[ 75%] Built target foreach
Scanning dependencies of target parse_command_line
[ 81%] Building CXX object tests/CMakeFiles/parse_command_line.dir/parse_command_line.cc.o
Linking CXX executable options
[ 81%] Built target options
Scanning dependencies of target readme
[ 87%] Building CXX object tests/CMakeFiles/readme.dir/readme.cc.o
Linking CXX executable readme
In file included from /root/silicon/silicon_build/externals/iod/tests/deep_merge.cc:4:
In file included from /root/silicon/silicon_build/externals/iod/tests/../iod/json.hh:15:
/root/silicon/silicon_build/externals/iod/tests/../iod/json_unicode.hh:64:61: error: call to implicitly-deleted copy constructor of 'std::basic_stringstream<char>'
  wrap_json_input_stream(const iod::stringview& s) { return std::stringstream(s.to_std_string()); }
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/sstream:502:32: note: copy constructor of 'basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' is implicitly deleted because base class
      'basic_iostream<char, std::char_traits<char> >' has a deleted copy constructor
    class basic_stringstream : public basic_iostream<_CharT, _Traits>
                               ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/istream:796:7: note: copy constructor of 'basic_iostream<char, std::char_traits<char> >' is implicitly deleted because base class
      'basic_istream<char, std::char_traits<char> >' has a deleted copy constructor
    : public basic_istream<_CharT, _Traits>,
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/istream:58:27: note: copy constructor of 'basic_istream<char, std::char_traits<char> >' is implicitly deleted because base class
      'basic_ios<char, std::char_traits<char> >' has a deleted copy constructor
    class basic_istream : virtual public basic_ios<_CharT, _Traits>
                          ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/basic_ios.h:66:23: note: copy constructor of 'basic_ios<char, std::char_traits<char> >' is implicitly deleted because base class 'std::ios_base' has an inaccessible
      copy constructor
    class basic_ios : public ios_base
                      ^
In file included from /root/silicon/silicon_build/externals/iod/tests/deep_merge.cc:4:
In file included from /root/silicon/silicon_build/externals/iod/tests/../iod/json.hh:15:
/root/silicon/silicon_build/externals/iod/tests/../iod/json_unicode.hh:66:57: error: call to implicitly-deleted copy constructor of 'std::basic_stringstream<char>'
  wrap_json_input_stream(const std::string& s) { return std::stringstream(s); }
                                                        ^~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/sstream:502:32: note: copy constructor of 'basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' is implicitly deleted because base class
      'basic_iostream<char, std::char_traits<char> >' has a deleted copy constructor
    class basic_stringstream : public basic_iostream<_CharT, _Traits>
                               ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/istream:796:7: note: copy constructor of 'basic_iostream<char, std::char_traits<char> >' is implicitly deleted because base class
      'basic_istream<char, std::char_traits<char> >' has a deleted copy constructor
    : public basic_istream<_CharT, _Traits>,
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/istream:58:27: note: copy constructor of 'basic_istream<char, std::char_traits<char> >' is implicitly deleted because base class
      'basic_ios<char, std::char_traits<char> >' has a deleted copy constructor
    class basic_istream : virtual public basic_ios<_CharT, _Traits>
                          ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/basic_ios.h:66:23: note: copy constructor of 'basic_ios<char, std::char_traits<char> >' is implicitly deleted because base class 'std::ios_base' has an inaccessible
      copy constructor
    class basic_ios : public ios_base
                      ^
In file included from /root/silicon/silicon_build/externals/iod/tests/deep_merge.cc:4:
In file included from /root/silicon/silicon_build/externals/iod/tests/../iod/json.hh:15:
/root/silicon/silicon_build/externals/iod/tests/../iod/json_unicode.hh:68:50: error: call to implicitly-deleted copy constructor of 'std::basic_stringstream<char>'
  wrap_json_input_stream(const char* s) { return std::stringstream(std::string(s)); }
                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/sstream:502:32: note: copy constructor of 'basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' is implicitly deleted because base class
      'basic_iostream<char, std::char_traits<char> >' has a deleted copy constructor
    class basic_stringstream : public basic_iostream<_CharT, _Traits>
                               ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/istream:796:7: note: copy constructor of 'basic_iostream<char, std::char_traits<char> >' is implicitly deleted because base class
      'basic_istream<char, std::char_traits<char> >' has a deleted copy constructor
    : public basic_istream<_CharT, _Traits>,
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/istream:58:27: note: copy constructor of 'basic_istream<char, std::char_traits<char> >' is implicitly deleted because base class
      'basic_ios<char, std::char_traits<char> >' has a deleted copy constructor
    class basic_istream : virtual public basic_ios<_CharT, _Traits>
                          ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/basic_ios.h:66:23: note: copy constructor of 'basic_ios<char, std::char_traits<char> >' is implicitly deleted because base class 'std::ios_base' has an inaccessible
      copy constructor
    class basic_ios : public ios_base
                      ^
[ 87%] Built target readme
Scanning dependencies of target tuple
[ 93%] Building CXX object tests/CMakeFiles/tuple.dir/tuple.cc.o
In file included from /root/silicon/silicon_build/externals/iod/tests/json.cc:7:
In file included from /root/silicon/silicon_build/externals/iod/tests/../iod/json.hh:15:
/root/silicon/silicon_build/externals/iod/tests/../iod/json_unicode.hh:64:61: error: call to implicitly-deleted copy constructor of 'std::basic_stringstream<char>'
  wrap_json_input_stream(const iod::stringview& s) { return std::stringstream(s.to_std_string()); }
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/sstream:502:32: note: copy constructor of 'basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' is implicitly deleted because base class
      'basic_iostream<char, std::char_traits<char> >' has a deleted copy constructor
    class basic_stringstream : public basic_iostream<_CharT, _Traits>
                               ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/istream:796:7: note: copy constructor of 'basic_iostream<char, std::char_traits<char> >' is implicitly deleted because base class
      'basic_istream<char, std::char_traits<char> >' has a deleted copy constructor
    : public basic_istream<_CharT, _Traits>,
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/istream:58:27: note: copy constructor of 'basic_istream<char, std::char_traits<char> >' is implicitly deleted because base class
      'basic_ios<char, std::char_traits<char> >' has a deleted copy constructor
    class basic_istream : virtual public basic_ios<_CharT, _Traits>
                          ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/basic_ios.h:66:23: note: copy constructor of 'basic_ios<char, std::char_traits<char> >' is implicitly deleted because base class 'std::ios_base' has an inaccessible
      copy constructor
    class basic_ios : public ios_base
                      ^
In file included from /root/silicon/silicon_build/externals/iod/tests/json.cc:7:
In file included from /root/silicon/silicon_build/externals/iod/tests/../iod/json.hh:15:
/root/silicon/silicon_build/externals/iod/tests/../iod/json_unicode.hh:66:57: error: call to implicitly-deleted copy constructor of 'std::basic_stringstream<char>'
  wrap_json_input_stream(const std::string& s) { return std::stringstream(s); }
                                                        ^~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/sstream:502:32: note: copy constructor of 'basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' is implicitly deleted because base class
      'basic_iostream<char, std::char_traits<char> >' has a deleted copy constructor
    class basic_stringstream : public basic_iostream<_CharT, _Traits>
                               ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/istream:796:7: note: copy constructor of 'basic_iostream<char, std::char_traits<char> >' is implicitly deleted because base class
      'basic_istream<char, std::char_traits<char> >' has a deleted copy constructor
    : public basic_istream<_CharT, _Traits>,
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/istream:58:27: note: copy constructor of 'basic_istream<char, std::char_traits<char> >' is implicitly deleted because base class
      'basic_ios<char, std::char_traits<char> >' has a deleted copy constructor
    class basic_istream : virtual public basic_ios<_CharT, _Traits>
                          ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/basic_ios.h:66:23: note: copy constructor of 'basic_ios<char, std::char_traits<char> >' is implicitly deleted because base class 'std::ios_base' has an inaccessible
      copy constructor
    class basic_ios : public ios_base
                      ^
In file included from /root/silicon/silicon_build/externals/iod/tests/json.cc:7:
In file included from /root/silicon/silicon_build/externals/iod/tests/../iod/json.hh:15:
/root/silicon/silicon_build/externals/iod/tests/../iod/json_unicode.hh:68:50: error: call to implicitly-deleted copy constructor of 'std::basic_stringstream<char>'
  wrap_json_input_stream(const char* s) { return std::stringstream(std::string(s)); }
                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/sstream:502:32: note: copy constructor of 'basic_stringstream<char, std::char_traits<char>, std::allocator<char> >' is implicitly deleted because base class
      'basic_iostream<char, std::char_traits<char> >' has a deleted copy constructor
    class basic_stringstream : public basic_iostream<_CharT, _Traits>
                               ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/istream:796:7: note: copy constructor of 'basic_iostream<char, std::char_traits<char> >' is implicitly deleted because base class
      'basic_istream<char, std::char_traits<char> >' has a deleted copy constructor
    : public basic_istream<_CharT, _Traits>,
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/istream:58:27: note: copy constructor of 'basic_istream<char, std::char_traits<char> >' is implicitly deleted because base class
      'basic_ios<char, std::char_traits<char> >' has a deleted copy constructor
    class basic_istream : virtual public basic_ios<_CharT, _Traits>
                          ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/basic_ios.h:66:23: note: copy constructor of 'basic_ios<char, std::char_traits<char> >' is implicitly deleted because base class 'std::ios_base' has an inaccessible
      copy constructor
    class basic_ios : public ios_base
                      ^
3 errors generated.
tests/CMakeFiles/deep_merge.dir/build.make:54: recipe for target 'tests/CMakeFiles/deep_merge.dir/deep_merge.cc.o' failed
make[2]: *** [tests/CMakeFiles/deep_merge.dir/deep_merge.cc.o] Error 1
CMakeFiles/Makefile2:363: recipe for target 'tests/CMakeFiles/deep_merge.dir/all' failed
make[1]: *** [tests/CMakeFiles/deep_merge.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
Linking CXX executable tuple
[ 93%] Built target tuple
3 errors generated.
tests/CMakeFiles/json.dir/build.make:54: recipe for target 'tests/CMakeFiles/json.dir/json.cc.o' failed
make[2]: *** [tests/CMakeFiles/json.dir/json.cc.o] Error 1
CMakeFiles/Makefile2:468: recipe for target 'tests/CMakeFiles/json.dir/all' failed
make[1]: *** [tests/CMakeFiles/json.dir/all] Error 2
Linking CXX executable parse_command_line
[ 93%] Built target parse_command_line
Makefile:117: recipe for target 'all' failed
make: *** [all] Error 2
Cannot install /root/silicon_build.

I successfully installed one if previous versions of silicon and iod on the same machine with the same OS before. What I am doing wrong?

MSVC 14 compatibility

I tried to compile this with VS2015 Update 1 and, lo and behold, it failed to compile. The first place it fell over is the line below, with enable_if_t:
https://github.com/matt-42/iod/blob/master/iod/grammar.hh#L97

  decltype(auto) exp_transform_iterate(E& exp, F map,
                             C ctx,
                             std::enable_if_t<!callable_with<F, E&, C>::value and
                             !has_transform_iterate<E>::value>* = 0)

I'm just diving back into C++ after several years away, so this syntax is quite foreign. Specifically, MSVC fails at the and (expecting >). Is this a specific C++14 feature that VS2015 hasn't implemented? I took a look a brief look at SFINAE and enable_if_t but couldn't find any relevant compatibility shortcoming in the following table:

http://en.cppreference.com/w/cpp/compiler_support

Any help to get my bearings on what is happening here would be greatly appreciated (as I'm not actually expecting MSVC support).

FYI – alternative symbol generator/extractor CLI tool

It’s a work in progress but I thought you might be interested:

https://github.com/fish2000/iod-symbolizer/

… I wrote it to e.g.: conditionally extract all symbols from .hpp/.hh/.cpp/.cc/.mm files in directories {aa/src, bb/src, aa/include, bb/include} – originally for one project but now I have spun it off. Written in Python, runs quick enough to use it as a CMake target 💯

Salud – thanks again for releasing your work

-Alex

Conan package

Hello,
Do you know about Conan?
Conan is modern dependency manager for C++. And will be great if your library will be available via package manager for other developers.

Here you can find example, how you can create package for the library.

If you have any questions, just ask :-)

symbol attributes assignee types

Can symbol's attributes value be lambda or std::bind objects? like:
_id(_some_handle=[]() { ... }
and can we access the sio(or symbol) within the lambda? like:
_id(_some_handle=[this]() { ... }

thanks!

call to 'iod_attr_to_json' is ambiguous

I'm getting the following error when trying to call iod_to_json() function:

g++ -o example example.cc -std=c++11
In file included from example.cc:4:
./iod_json.hh:108:5: error: call to 'iod_attr_to_json' is ambiguous
    iod_attr_to_json(*static_cast<const iod_object<Tail...>*>(&o), ss);
    ^~~~~~~~~~~~~~~~


./iod_json.hh:108:5: note: in instantiation of function template specialization 'iod_internals::iod_attr_to_json<cities_attr<std::initializer_list<const char *> >,
      cars_attr<std::initializer_list<iod_object<name_attr<const char *>, model_attr<const char *>, xxx_attr<int> > > > >' requested here
    iod_attr_to_json(*static_cast<const iod_object<Tail...>*>(&o), ss);
    ^
./iod_json.hh:108:5: note: in instantiation of function template specialization 'iod_internals::iod_attr_to_json<age_attr<int>, cities_attr<std::initializer_list<const char *> >,
      cars_attr<std::initializer_list<iod_object<name_attr<const char *>, model_attr<const char *>, xxx_attr<int> > > > >' requested here
    iod_attr_to_json(*static_cast<const iod_object<Tail...>*>(&o), ss);
    ^
./iod_json.hh:108:5: note: in instantiation of function template specialization 'iod_internals::iod_attr_to_json<name_attr<const char *>, age_attr<int>,
      cities_attr<std::initializer_list<const char *> >, cars_attr<std::initializer_list<iod_object<name_attr<const char *>, model_attr<const char *>, xxx_attr<int> > > > >'
      requested here
    iod_attr_to_json(*static_cast<const iod_object<Tail...>*>(&o), ss);
    ^
./iod_json.hh:81:5: note: in instantiation of function template specialization 'iod_internals::iod_attr_to_json<xxx_attr<std::initializer_list<const char *> >, name_attr<const char
      *>, age_attr<int>, cities_attr<std::initializer_list<const char *> >, cars_attr<std::initializer_list<iod_object<name_attr<const char *>, model_attr<const char *>,
      xxx_attr<int> > > > >' requested here
    iod_attr_to_json(o, ss);
    ^
./iod_json.hh:89:5: note: in instantiation of function template specialization 'iod_internals::iod_to_json<xxx_attr<std::initializer_list<const char *> >, name_attr<const char *>,
      age_attr<int>, cities_attr<std::initializer_list<const char *> >, cars_attr<std::initializer_list<iod_object<name_attr<const char *>, model_attr<const char *>, xxx_attr<int> >
      > > >' requested here
    iod_to_json(o, ss);
    ^
./iod_json.hh:322:25: note: in instantiation of function template specialization 'iod_internals::iod_to_json<xxx_attr<std::initializer_list<const char *> >, name_attr<const char *>,
      age_attr<int>, cities_attr<std::initializer_list<const char *> >, cars_attr<std::initializer_list<iod_object<name_attr<const char *>, model_attr<const char *>, xxx_attr<int> >
      > > >' requested here
  return iod_internals::iod_to_json(o);
                        ^
example.cc:35:22: note: in instantiation of function template specialization 'iod_to_json<xxx_attr<std::initializer_list<const char *> >, name_attr<const char *>, age_attr<int>,
      cities_attr<std::initializer_list<const char *> >, cars_attr<std::initializer_list<iod_object<name_attr<const char *>, model_attr<const char *>, xxx_attr<int> > > > >'
      requested here
  std::string json = iod_to_json(person);
                     ^
./iod_json.hh:94:8: note: candidate function [with T = cars_attr<std::initializer_list<iod_object<name_attr<const char *>, model_attr<const char *>, xxx_attr<int> > > >]
  void iod_attr_to_json(const iod_object<T>& o, std::stringstream& ss)
       ^
./iod_json.hh:102:8: note: candidate function [with T = cars_attr<std::initializer_list<iod_object<name_attr<const char *>, model_attr<const char *>, xxx_attr<int> > > >, Tail = <>]
  void iod_attr_to_json(const iod_object<T, Tail...>& o, std::stringstream& ss)
       ^
1 error generated.

Just to know, I'm using MacOS + clang (Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn))

Why are there added underscores in definitions?

I removed it and everything seems fine.
I think this is easier and more readable to use :

auto person = iod(
    name = "Philippe"
);

Is there a reason for the added underscore in the definitions?

Cannot make iod

Centos 7, clang5

$ cmake ..
-- The C compiler identification is Clang 5.0.1
-- The CXX compiler identification is Clang 5.0.1
-- Check for working C compiler: /usr/local/bin/clang
-- Check for working C compiler: /usr/local/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/local/bin/clang++
-- Check for working CXX compiler: /usr/local/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.53.0
-- Configuring done
-- Generating done
-- Build files have been written to: /opt/data/Soft/clang/iod/ff

$ cmake --build .
Scanning dependencies of target iod_generate_symbols
[ 3%] Building CXX object tools/CMakeFiles/iod_generate_symbols.dir/iod_generate_symbols.cc.o
[ 6%] Linking CXX executable iod_generate_symbols
[ 6%] Built target iod_generate_symbols
Scanning dependencies of target parse_command_line
[ 9%] Building CXX object tests/CMakeFiles/parse_command_line.dir/parse_command_line.cc.o
In file included from /opt/data/Soft/clang/iod/tests/parse_command_line.cc:10:
In file included from /opt/data/Soft/clang/iod/tests/symbols.hh:2:
In file included from /opt/data/Soft/clang/iod/tests/../iod/symbol.hh:5:
In file included from /opt/data/Soft/clang/iod/tests/../iod/grammar.hh:6:
In file included from /opt/data/Soft/clang/iod/tests/../iod/foreach.hh:4:
In file included from /opt/data/Soft/clang/iod/tests/../iod/callable_traits.hh:3:
In file included from /opt/data/Soft/clang/iod/tests/../iod/typelist.hh:4:
/opt/data/Soft/clang/iod/tests/../iod/tuple_utils.hh:48:41: error: no template named 'enable_if_t' in namespace 'std'; did you mean 'enable_if'?
decltype(auto) arg_get_by_type_( std::enable_if_t<!std::is_same<E,
~~~~~^~~~~~~~~~~
enable_if
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/type_traits:1766:12: note: 'enable_if' declared here
struct enable_if
^
In file included from /opt/data/Soft/clang/iod/tests/parse_command_line.cc:10:
In file included from /opt/data/Soft/clang/iod/tests/symbols.hh:2:
In file included from /opt/data/Soft/clang/iod/tests/../iod/symbol.hh:5:
In file included from /opt/data/Soft/clang/iod/tests/../iod/grammar.hh:6:
In file included from /opt/data/Soft/clang/iod/tests/../iod/foreach.hh:4:
In file included from /opt/data/Soft/clang/iod/tests/../iod/callable_traits.hh:3:
In file included from /opt/data/Soft/clang/iod/tests/../iod/typelist.hh:4:
/opt/data/Soft/clang/iod/tests/../iod/tuple_utils.hh:49:41: error: no template named 'decay_t' in namespace 'std'; did you mean 'decay'?
std::decay_t>::value>*,
~~~~~^~~~~~~
decay

How can i fix it?

New

Hello, how I can define _new symbol?

Command line options with an embedded dash

Hi, is it possible to parse command line options like --my-switch for example? I had a look at the code and I think the answer is no, but maybe I missed something? Or is there a workaround?

GCC 4.9 support

With GCC 4.9.3 (debian linux) I get compilation errors related to the lack of copy constructor in std::stringstream:

Scanning dependencies of target di
In file included from /home/manuel-sanchez/Documentos/iod/tests/../iod/json.hh:15:0,
                 from /home/manuel-sanchez/Documentos/iod/tests/deep_merge.cc:4:
/home/manuel-sanchez/Documentos/iod/tests/../iod/json_unicode.hh: In function ‘decltype(auto) iod::wrap_json_input_stream(const iod::stringview&)’:
/home/manuel-sanchez/Documentos/iod/tests/../iod/json_unicode.hh:64:96: error: use of deleted function ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)’
   wrap_json_input_stream(const iod::stringview& s) { return std::stringstream(s.to_std_string()); }
                                                                                                ^
In file included from /home/manuel-sanchez/Documentos/iod/tests/../iod/json.hh:9:0,
                 from /home/manuel-sanchez/Documentos/iod/tests/deep_merge.cc:4:
/usr/include/c++/4.9/sstream:502:11: note: ‘std::basic_stringstream<char>::basic_stringstream(const std::basic_stringstream<char>&)’ is implicitly deleted because the default definition would be ill-formed:
     class basic_stringstream : public basic_iostream<_CharT, _Traits>
           ^
/usr/include/c++/4.9/sstream:502:11: error: use of deleted function ‘std::basic_iostream<char>::basic_iostream(const std::basic_iostream<char>&)’
In file included from /usr/include/c++/4.9/iostream:40:0,
                 from /home/manuel-sanchez/Documentos/iod/tests/deep_merge.cc:1:
/usr/include/c++/4.9/istream:795:11: note: ‘std::basic_iostream<char>::basic_iostream(const std::basic_iostream<char>&)’ is implicitly deleted because the default definition would be ill-formed:
     class basic_iostream
           ^

What I can say from the output is that it seems that for some reason that function is not triggering RVO and the stdlibc++ stream has no move constructor (So the compiler picks the copy ctor instead).

UPDATE: After adding gcc 4.9 to the build matrix I see that the "issue" is just that the library no longer supports GCC 4.9 in its current form.

Do you have plans to maintain compatibility with GCC 4.9?

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.