Turning boost dependence optional. - #3
Conversation
* Included in CMakeLists option to enable/disable use of boost (and check if it is found on system).
* Modified 'error.h' to use a custom 'format' (using variadic template) instead of boost::format.
* Created 'optional.h' to wrap 'boost/optional' (when using boost) or using custom optional (without boost).
* Changed 'repo.cpp' to use it
* Modified 'diff.cpp' to allow alternate between 'boost::flatmap'(when available) or 'std::unordered_map'
* Modified examples (log.cpp and rev-parse.cpp) to align with the changes.
|
Thank you for the contribution! |
|
Thanks for the feedback. About using Thanks for the tips about my handcrafted In relation to ...
explicit commit_tree_error(git_oid const & id)
: error_t(std::string("Could not get tree for commit ").append(id_to_str(id)))
{}This is simpler. However i think is more ugly and i don't know how much faster. One last thing. Do you wanna remove the boost dependence completely? Or do you prefer keeping it as optional dependence? |
|
Yes, I'd like to see implementation of the class template<typename... Args>
std::string format(const char * fmt, Args&& ... args)
{
auto size = std::snprintf(nullptr, 0, fmt, args...);
std::string result(size, 0);
std::snprintf(&result[0], size + 1, fmt, args...);
return result;
}I prefer to keep optional dependency on Boost, and I imagine that libgit2cpp will contain some code like the following namespace git {
namespace internal
{
#if [std implementation available]
using std::optional;
#elif [std::experimental implementation available]
using std::experimental::optional;
#elif [boost available]
using boost::optional;
#else
own optional implementation
#endif
#if [boost available]
namespace details
{
template<typename... Args>
boost::format eat_args(boost::format fmt, Args&& ... args);
boost::format eat_args(boost::format fmt)
{
return std::move(fmt);
}
template<typename Arg, typename... Rest>
boost::format eat_args(boost::format fmt, Arg && arg, Rest&& ... rest)
{
return eat_args(fmt % arg, rest...);
}
}
#endif
template<typename... Args>
std::string format(const char * fmt, Args&& ... args)
{
#if [boost available]
return str(details::eat_args(boost::format(fmt), args...));
#else
own implementation
#endif
}
}} |
* Changed custom `optional` implementation to avoid dynamic allocation
* Changed `format` implementation to use `std::snprintf` instead of stream
* Using `boost::format` if using boost
* Moved 'internal' headers to specific folder
* Minor changes (in `examples/log.cpp` and `src/repo.cpp`) to adapt to new implementations.
|
I finished the changes we discussed. |
|
I squashed your commits simplified |
Hello @AndreyG,
i have found your library, while searching to some c++ wrapper for libgit2.
Btw, congratulations, it looks very nice.
Well, i saw (when trying to compile it) that there was some dependencies with boost.
To avoid requiring boost (i plan to build a library that uses libgit2cpp), i am submitting these changes.
As you can see, is still possible to use boost with a build option (-DUSE_BOOST=ON). But, now is an optional requirement.
I hope that you find useful.
Below the detailed changes.