After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 777791 - Glibmm Variant does not feature templates for std::tuple
Glibmm Variant does not feature templates for std::tuple
Status: RESOLVED FIXED
Product: glibmm
Classification: Bindings
Component: general
2.51.x
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2017-01-26 13:34 UTC by Alexander Rössler
Modified: 2017-09-14 09:31 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch adds Glib::Variant templates for std::tuple (5.89 KB, patch)
2017-01-26 13:36 UTC, Alexander Rössler
needs-work Details | Review

Description Alexander Rössler 2017-01-26 13:34:04 UTC
Glib::Variant does not feature templates for std::tuple. This makes it impossible to create Glib tuples just using Glibmm, which makes it hard to use Giomm::DBus with tuple types.

I tried following workarounds:

Glib::Variant< std::map<guint16, Glib::VariantContainerBase> > driver_map;
m_userman->get_cached_property(driver_map, "DriverList");
auto data = driver_map.get();
Throws following error:
 
In file included from /usr/include/glibmm-2.4/glibmm/containerhandle_shared.h:25:0,
from /usr/include/glibmm-2.4/glibmm/object.h:34,
from /usr/include/giomm-2.4/giomm/dbusconnection.h:29,
from dbushandler.h:3,
from dbushandler.cpp:1:
/usr/include/glibmm-2.4/glibmm/variant.h: In instantiation of ‘std::pair<_T1, _T2> Glib::Variant<std::pair<_T1, _T2> >::get() const [with K = short int; V = Glib::VariantContainerBase]’:
/usr/include/glibmm-2.4/glibmm/variant.h:1722:5: required from ‘std::map<K, V> Glib::Variant<std::map<K, V> >::get() const [with K = short int; V = Glib::VariantContainerBase]’
dbushandler.cpp:88:36: required from here
/usr/include/glibmm-2.4/glibmm/variant.h:1549:48: error: ‘class Glib::Variant<Glib::VariantContainerBase>’ has no member named ‘get’
std::pair<K, V> result(key.get(), value.get());
^
/usr/include/glibmm-2.4/glibmm/variant.h: In instantiation of ‘static const Glib::VariantType& Glib::Variant<std::pair<_T1, _T2> >::variant_type() [with K = short int; V = Glib::VariantContainerBase]’:
/usr/include/glibmm-2.4/glibmm/variant.h:1643:71: required from ‘static const Glib::VariantType& Glib::Variant<std::map<K, V> >::variant_type() [with K = short int; V = Glib::VariantContainerBase]’
/usr/include/glibmm-2.4/glibmm/variant.h:1731:53: required from ‘Glib::VariantIter Glib::Variant<std::map<K, V> >::get_iter() const [with K = short int; V = Glib::VariantContainerBase]’
/usr/include/glibmm-2.4/glibmm/variant.h:1717:30: required from ‘std::map<K, V> Glib::Variant<std::map<K, V> >::get() const [with K = short int; V = Glib::VariantContainerBase]’
dbushandler.cpp:88:36: required from here
/usr/include/glibmm-2.4/glibmm/variant.h:1520:29: error: ‘variant_type’ is not a member of ‘Glib::Variant<Glib::VariantContainerBase>’
Variant<V>::variant_type().gobj()));

I also tried this second approach:​
​
Glib::Variant< std::map<guint16, Glib::Variant<std::vector<Glib::VariantBase> > > > driver_map;
m_userman->get_cached_property(driver_map, "DriverList");
auto data = driver_map.get();
​
Which throws following error at runtime:
(launcher:10778): GLib-CRITICAL **: the GVariant format string 'a{qv}' has a type of 'a{qv}' but the given value has a type of 'a{q(qsb)}'

(launcher:10778): GLib-CRITICAL **: g_variant_get: assertion 'valid_format_string (format_string, TRUE, value)' failed

(launcher:10778): GLib-CRITICAL **: g_variant_iter_next_value: assertion 'is_valid_iter (iter)' failed
Comment 1 Alexander Rössler 2017-01-26 13:36:28 UTC
Created attachment 344322 [details] [review]
Patch adds Glib::Variant templates for std::tuple

Please review the attached patch and let me know what else needs to be done.
Comment 2 Kjell Ahlstedt 2017-02-01 13:55:50 UTC
Your patch looks good in general. Just a few comments:

"Gets a specific dictionary entry from the string array." looks like something
you have copied but not changed properly.

Indentation shall be 2 spaces per indentation level.
Don't use tab characters. (I don't think you have.)

If you want to do more, it would be great if you could add a test or two to
glibmm/tests/glibmm_variant/main.cc.
Unfortunately, that file is not a very good example of a test. An ideal test
case, run by 'make check', shall return EXIT_FAILURE if a test fails.
You can choose to do it like the rest of the file, or do it better.
Comment 3 Kjell Ahlstedt 2017-03-06 14:25:28 UTC
I have pushed your patch with some changes in comments and white space,
https://git.gnome.org/browse/glibmm/commit/?id=6e205b721ebb26264bb00bdf294e04255de34f34
and a patch with tests,
https://git.gnome.org/browse/glibmm/commit/?id=2f80fe4276c9ed4de493dc88218187d8c685d06a
Comment 4 Kjell Ahlstedt 2017-09-08 11:42:08 UTC
Now I have also pushed the two patches to the glibmm-2-54 branch.