Anteru's blog
  • Consulting
  • Research
    • Assisted environment probe placement
    • Assisted texture assignment
    • Edge-Friend: Fast and Deterministic Catmull-Clark Subdivision Surfaces
    • Error Metrics for Smart Image Refinement
    • High-Quality Shadows for Streaming Terrain Rendering
    • Hybrid Sample-based Surface Rendering
    • Interactive rendering of Giga-Particle Fluid Simulations
    • Quantitative Analysis of Voxel Raytracing Acceleration Structures
    • Real-time Hybrid Hair Rendering
    • Real-Time Procedural Generation with GPU Work Graphs
    • Scalable rendering for very large meshes
    • Spatiotemporal Variance-Guided Filtering for Motion Blur
    • Subpixel Reconstruction Antialiasing
    • Tiled light trees
    • Towards Practical Meshlet Compression
  • About
  • Archive

Boost::Signal inside a std::map

December 06, 2005
  • Programming
approximately 1 minutes to read

Recently, I came across a problem with Boost::Signal. I wanted to use them inside a std::map so I could map signals to categories, and this turned out to be not as simple as one might think.

Problem

The main problem is that boost::signal is noncopyable, meaning you can’t use the assignment operator “=” at all. This prevents the straightforward use in any STL container, as those depend on the assignment operator. You can of course have explicit instances of boost::signal, but you can’t use them directly in a container, let alone add and remove them dynamically.

Solution

The first solution I tried was to store pointers (in my case, boost::shared_ptr<>) to the signals, and fill the map with those. This works, but it is a bit cumbersome to maintain all the pointers and have new all around the place. Fortunately, another boost library comes to the rescue, boost::ptr_map from the Boost Pointer Container library. It has two specialities I came across (using boost 1.33.1 beta from 8th November).

  • Its insert () function takes a non-const reference as key, unlike the std::map`. Be aware of that, as it can lead to hard-to-find compiler errors.
  • The dereferencing was non-standard, in my case I had to use (iterator_to_ptr_map)(params_for_signal), I supposed I would have to add some “*” somewhere but somehow the map didn’t need it.

Will try with Boost 1.33.1 final and report if there is any difference to the beta.

Previous post
Next post

Recent posts

  • Data formats: Why CSV and JSON aren't the best
    Posted on 2024-12-29
  • Replacing cron with systemd-timers
    Posted on 2024-04-21
  • Open Source Maintenance
    Posted on 2024-04-02
  • Angular, Caddy, Gunicorn and Django
    Posted on 2023-10-21
  • Effective meetings
    Posted on 2022-09-12
  • Older posts

Find me on the web

  • GitHub
  • GPU database
  • Projects

Follow me

Anteru NIV_Anteru
Contents © 2005-2025
Anteru
Imprint/Impressum
Privacy policy/Datenschutz
Made with Liara
Last updated February 20, 2019