I'm sure there has been similar discussion before but it seems to be on
other API, I propose a const_data() API to msg_t in order to permit const
correctness in higher APIs.  A primary example being CZMQ's zmsgdup API (
zmsg_copy).

Is there a better way of doing this in C++?

-- 
Steve-o
From 06a09398d2ff8ac328e98b14a4855c9163101917 Mon Sep 17 00:00:00 2001
From: Steven McCoy <[email protected]>
Date: Thu, 26 May 2011 20:20:21 -0400
Subject: [PATCH] Add const_data API for const correctness.


Signed-off-by: Steven McCoy <[email protected]>
---
 src/msg.cpp |    5 +++++
 src/msg.hpp |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/src/msg.cpp b/src/msg.cpp
index 84ca3e2..e9d4c91 100644
--- a/src/msg.cpp
+++ b/src/msg.cpp
@@ -195,6 +195,11 @@ void *zmq::msg_t::data ()
     }
 }
 
+const void *zmq::msg_t::const_data ()
+{
+    return data ();
+}
+
 size_t zmq::msg_t::size ()
 {
     //  Check the validity of the message.
diff --git a/src/msg.hpp b/src/msg.hpp
index 466a96a..9ff4e85 100644
--- a/src/msg.hpp
+++ b/src/msg.hpp
@@ -61,6 +61,7 @@ namespace zmq
         int move (msg_t &src_);
         int copy (msg_t &src_);
         void *data ();
+         const void *const_data ();
         size_t size ();
         unsigned char flags ();
         void set_flags (unsigned char flags_);
-- 
1.7.4.1

_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to