hyperrealm / libconfig

C/C++ library for processing configuration files
https://hyperrealm.github.io/libconfig/
GNU Lesser General Public License v2.1
1.1k stars 360 forks source link

Can you let me know why libconfig forbid copy? #163

Closed nickhuangxinyu closed 3 years ago

nickhuangxinyu commented 4 years ago

libconfig is a great tool, but no copy design cause a lot of inconvience for me, for example:

if i have a config that record all stock's config(like: fee_rate, stock_price ....)

I write all stocks' config in one config file

I want to build a worker to save this into a map (key is stock name, value is libconfig::Setting for this stock), it will fail, because "=" is private

I think libconfig is a masterpiece, So, what is the purpose to make = and contructor private?(forbid to copy)

hyperrealm commented 3 years ago

This is because a copy could potentially be an expensive operation and it may not be immediately obvious to a developer that assigning one setting to another will perform a deep copy.

There is a function in contrib/copy_setting.c that will do a deep copy.

keineahnung2345 commented 2 years ago

It seems the deep copy function is only for C, not for C++?