Monday, January 14, 2019

Digest for comp.lang.c++@googlegroups.com - 14 updates in 5 topics

Nikki Locke <nikki@trumphurst.com>: Jan 14 11:23PM

Available C++ Libraries FAQ
 
URL: http://www.trumphurst.com/cpplibs/
 
This is a searchable list of libraries and utilities (both free
and commercial) available to C++ programmers.
 
If you know of a library which is not in the list, why not fill
in the form at http://www.trumphurst.com/cpplibs/cppsub.php
 
Maintainer: Nikki Locke - if you wish to contact me, please use the form on the website.
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jan 15 12:17AM +0100

On 12.01.2019 16:26, Unto Sten wrote:
 
> Okay, I have to study more about lambdas. Could you refer to some
> C++ example code that demonstrates the functor property of lambda
> functions?
 
The following code aids in unwrapping the exception messages of a C++11
exception that can contain a nested exception that can contain..., and
so on. In this code cppx::C_str is a `typedef` of `char const*`. Usually
it's ungood to name pointer types but I've found this one useful, so.
 
 
------------------------------------------------------------------------
#pragma once // Source encoding: UTF-8 with BOM (π is a lowercase
Greek "pi").
 
#include <cppx-core/collections/is_empty.hpp> //
cppx::is_empty
#include <cppx-core/core-language/$use_from_namespace.hpp> // CPPX_USE_STD
#include <cppx-core/text/C_str_.hpp> // cppx::C_str
 
#include <exception> // std::(exception, rethrow_exception)
#include <functional> // std::function
#include <utility> // std::move
 
namespace cppx
{
CPPX_USE_STD( exception, function, move, rethrow_if_nested, string );
 
inline void call_with_description_lines_from(
const exception& x,
const function<void( const C_str )>& f
)
{
f( x.what() );
try
{
rethrow_if_nested( x );
}
catch( const exception& rx )
{
call_with_description_lines_from( rx, f );
}
catch( ... )
{
f( "<a non-standard exception>" );
}
}
 
inline auto description_lines_from( const exception& x )
-> string
{
string result;
const auto add = [&]( const C_str s ) -> void
{
if( not is_empty( result ) )
{
result += '\n';
}
result += s;
};
call_with_description_lines_from( x, add );
return result;
}
 
} // namespace cppx
------------------------------------------------------------------------
 
 
Here the lambda in `description_lines_from` adds lines of text to the
local variable in that function, `result`.
 
 
[snip]
 
 
Cheers!,
 
- Alf
David Brown <david.brown@hesbynett.no>: Jan 14 05:12PM +0100

On 14/01/2019 15:58, fir wrote:
 
<garbled nonsense>
 
If you want to be taken seriously, learn to write. If you can't do so
in English, do it in your native language and use Google Translate (no
one minds imperfect English - we are all aware that using a second
language is difficult). It works much better than dictating to your cat
and having it walk on your keyboard.
 
Until you learn to communicate, you are just wasting your time and
everyone else's time.
 
If you want to understand about what the C language is and what it is
not, or about the differences between C implementations and the C
language, or about how to use C correctly and efficiently, then I and
many others in this group will help you and answer your questions. But
if you have fixed but incorrect ideas, and are only here to write
insults and gibberish, you'll learn nothing.
"Öö Tiib" <ootiib@hot.ee>: Jan 14 08:24AM -0800

On Monday, 14 January 2019 16:13:15 UTC+2, Rick C. Hodgin wrote:
 
> https://www.biblegateway.com/passage/?search=Matthew+7%3A16-20&version=KJV
 
> 16 Ye shall know them by their fruits. Do men gather grapes
> of thorns, or figs of thistles?
 
Exactly.
* How many Christians are on planet Earth? There are
about 2.2 billions by most statistics.
* How many of those are followers of teachings of yours?
None. And there will never be any.
* Why? Since you can't even properly pretend to grow grapes
or figs or what these were.
 
Your "teaching" is like worst parody of one. But you somehow
read from these words of Jesus that you do it correctly? :D
 
> they move over time ... the pattern will become clear with some
> investigation.
 
> C"Alive", Öö Tiib. Why did I choose the name "Alive"?
 
Yes with their words they make beautiful fruit like "C Alive".
 
But when we look ... what such fruit we see there?
Hmm ... three things, none made by Rick C. Hodgin:
https://www.ca.com/gb/products/ca-live-api-creator.html
https://download.cnet.com/CALive/3000-31713_4-76337978.html
https://www.synapseindia.com/portfolio/calive
 
So where are your "grapes and figs"? Nowhere. Stop blaming
Jesus in your utter lack of self awareness. Also, you are
not mislead by "Enemy" or "Sin", you are mislead by
yourself, by your refusal to observe objectively what you
are, how others see your actions and what are actual results
of those.
fir <profesor.fir@gmail.com>: Jan 14 08:31AM -0800

W dniu poniedziałek, 14 stycznia 2019 17:12:46 UTC+1 użytkownik David Brown napisał:
> many others in this group will help you and answer your questions. But
> if you have fixed but incorrect ideas, and are only here to write
> insults and gibberish, you'll learn nothing.
 
badge snapped..
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jan 14 08:54AM -0800

On Monday, January 14, 2019 at 11:25:08 AM UTC-5, Öö Tiib wrote:
> Your "teaching" is like worst parody of one.
 
Which part?
 
> But you somehow
> read from these words of Jesus that you do it correctly? :D
 
It's possible I'm incorrect. Identify where I'm doing something
incorrectly and we'll investigate it and sort it out based on
Biblical teachings / writings, along with prior well-known teach-
ers and pastors from previous centuries.
 
My goal is not to teach "Rick's teaching," but to teach the true
gospel of Jesus Christ. My teachings come from the Bible, as
well as many historical pastors who have given me input through
their recorded sermons over the years.
 
I have studied and brought those teachings to bear in my life,
though I still fall short in many areas, and I teach others (in-
cluding myself) to move and do rightly.
 
Show me where I'm wrong and we'll investigate it all the way to
its foundations and see what's what.
 
--
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jan 14 11:30AM -0800

On Monday, January 14, 2019 at 11:25:08 AM UTC-5, Öö Tiib wrote:
 
> Exactly.
> * How many Christians are on planet Earth? There are
> about 2.2 billions by most statistics.
 
The thing about Christians is this: We are not called to be of
this world, but are rather called out of this world. Listen to
this prayer Jesus makes for those He left behind when He ascended
into Heaven to be seated at the right hand of God:
 
https://www.biblegateway.com/passage/?search=John+17&version=NIV;KJV
 
14 I have given them thy word; and the world hath hated them,
because they are not of the world, even as I am not of the
world.
15 I pray not that thou shouldest take them out of the world,
but that thou shouldest keep them from the evil.
16 They are not of the world, even as I am not of the world.
17 Sanctify them through thy truth: thy word is truth.
18 As thou hast sent me into the world, even so have I also
sent them into the world.
19 And for their sakes I sanctify myself, that they also might
be sanctified through the truth.
==> 20 Neither pray I for these alone, but for them also which
shall believe on me through their word;
21 That they all may be one; as thou, Father, art in me, and
I in thee, that they also may be one in us:
==> that the world may believe that thou hast sent me.
 
We are hated, despised, called all names, cast down as evil, be-
cause we are not of this world. We are called unto a holy call-
ing, a higher place, a spiritual place unto God.
 
https://www.biblegateway.com/passage/?search=Romans+8%3A36&version=NIV;KJV
 
36 As it is written, For thy sake we are killed all the day
long; we are accounted as sheep for the slaughter.
 
It is for this reason people will seek to kill us, and not for
other reasons.
 
Our lives are not our own. We were bought with a price, and we
honor God with our lives because of what He first did for us (at
the cross, and in our hearts and minds and lives).
 
A man alive in the 1700s wrote this:
 
"I once was lost, but now am found (referring to salvation),
was blind, but now I see (referring to the new spirit nature)."
 
It's from the song Amazing Grace. A former rude, profane, drunken
slave trader, a former man of the world and its vices, wrote those
words after being saved by Jesus Christ. He went on to become an
advocate for freeing the slaves in England in the late 1780s.
 
--
Rick C. Hodgin
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Jan 14 03:12PM -0800

On Monday, January 14, 2019 at 11:25:08 AM UTC-5, Öö Tiib wrote:
> Your "teaching" is like worst parody of one. But you somehow
> read from these words of Jesus that you do it correctly? :D
 
Here's a teaching from a pastor from this past weekend. He goes
through with passion conveying the same information I teach here.
You can't make it on your own. Christ calls out to each person
asking if He can save them. We are not saved by our own power or
ability, but by Christ reaching down into the cesspool of our sin-
soaked life and lifting us out of it by His mighty arm.
 
Jesus calls out to each person individually. He asks each person
IF He can save them. He teaches them the truth, warns of the con-
sequences of sin, and asks politely, repeatedly, if He can take
away their sin and save them:
 
https://www.youtube.com/watch?v=M5kYw42Fdf4
 
Watch this sermon and listen to the power and might of God applied
to the sinner's life (to my life, to everyone's life ... if we'll
receive Him into our life).
 
--
Rick C. Hodgin
hjkhboehm@gmail.com: Jan 14 09:34AM -0800

On Mon, Jan 14, 2019 at 6:23 AM Scott Lurndal wrote:
 
> Why a memcpy? Just code it directly as an assignment loop. byte-wise bulk copies are horribly
> inefficient.
 
I was talking about semantics, not implementation. Copying with larger granularity, as memcpy implementations usually do, is fine. Taking advantage of compiler knowledge about alignment is also fine. But we would only promise byte-level atomicity.
 
You can already code it as an assignment loop using memory_order_relaxed atomic accesses. That will become easier in some cases with atomic_ref. Coding it as non-atomic accesses is unlikely to ever be fine. By doing so, you're telling the compiler that it's OK to assume the underlying value won't be changed concurrently by another thread, which is incorrect. I don't think there is much (any?) interest on the committee for defining a "seqlock subset" of C++ that's OK to use in a racey way inside seqlocks. I don't see any way to do that without horribly complicating compiler optimization rules.
 
But that doesn't necessarily make the resulting code slower, except by disabling compiler optimizations that are likely to be incorrect in this context.
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Jan 14 01:43PM -0800

On 1/14/2019 6:22 AM, Scott Lurndal wrote:
>> existing memcpy impls should be okay, or rather easily adapted to work.
 
> Why a memcpy? Just code it directly as an assignment loop. byte-wise bulk copies are horribly
> inefficient.
 
It would be useful, or perhaps more "convenient", within the context of
any type of algorithm where the readers do not care about concurrent
writes because they use other means to determine 100% coherent atomic
reads of a state. This "very special" memcpy would ultimately behave as
if each "unit" was read using std::atomic::load with
std::memory_order_relaxed ordering. Very simple.
 
<quick pseudo-code, sorry for any typos>
_________________________________
// A readers local view of the state
struct local_view
{
unsigned long a;
short b;
unsigned int c;
};
 
 
// The shared state
struct seqlock_user_state
{
std::atomic<unsigned long> a;
std::atomic<short> b;
std::atomic<unsigned int> c;
 
// Take a local view of the state...
void snapshot(local_view& v) const
{
// Let's read the sucker!
v.a = a.load(std::memory_order_relaxed);
v.b = b.load(std::memory_order_relaxed);
v.c = c.load(std::memory_order_relaxed);
}
};
_________________________________
 
 
seqlock_user_state::snapshot works within the readers critical section
wrt seqlock. This does not show the version numbers, but instead focuses
on the state itself.
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Jan 14 01:53PM -0800

On 1/14/2019 1:43 PM, Chris M. Thomasson wrote:
>>>> Thomasson wrote:
>>>>> On 1/10/2019 2:02 PM, I wrote:
>>>>>> [Michael P. pointed me at this thread. ]
[...]
>      v.a = a.load(std::memory_order_relaxed);
>      v.b = b.load(std::memory_order_relaxed);
>      v.c = c.load(std::memory_order_relaxed);
 
 
Now, imagine a memcpy that just copies seqlock_user_state over to a
local_view in one simple shot, yet still had all of the guarantees of
the snapshot function? Imvho, that would be pretty darn convenient, at
least.
 
 
Michael Powell <mwpowellhtx@gmail.com>: Jan 14 08:03AM -0800

On Monday, January 14, 2019 at 7:39:30 AM UTC-5, Öö Tiib wrote:
> https://www.json.org/
> It is difficult to discuss stuff when terminology is
> pointlessly skewed by some part.
 
I agree; initially I went with "key" because it is that in context. However, I see your point.
 
 
 
> > At least at the moment, Object is represented by:
 
> > using object_t = std::vector<boost::tuple<key_t, value_t>>;
 
> Ok. It wasn't when I looked at your code.
 
The perseverance is appreciated. I've drafted a couple versions during the process working out a good, better, best approach.
 
 
> Yes, the whole idea of JSON is deeply recursive.
> That means we have to use another layer of
> indirection at spots of breaking the recursion.
 
Yes, I understand that.
 
> std::unique_ptr to not fully defined types at
> spots of breaking recursion. It is simple enough to
> use first at spots chosen by "best readability".
 
Well, I would, but for parser limitations. It works with boost::variant, from what I understand, and not std::variant.
 
> in sense that it is performance optimization ... for
> time when the thing works and so there is point
> to optimize it at all.
 
That said, I might consider something like enabling shared_ptr, for those times when I may need to "lift" a node from the tree for inspection, but I want to preserve the state of the node/tree.
 
> made it feel like lose-lose-lose choice. It was
> about 4 or 5 years ago, maybe spirit has improved
> in some aspects since then but I doubt it.
 
There are probably other parser stacks I could consider. However, for purposes of what I'm doing, I am running with what I know, so to speak, and I am fairly well versed in the Boost stack, Spirit, Qi, etc. X3 may be at a point where I mature my comprehension to encompass it, but the last time I checked, there were "issues" with the Microsoft compiler. This may have been resolved by this point, though, I just haven't spent the calories to verify that for myself.
 
> in object o can be set just with "o[n] = v;".
> The o[n] returns reference to value or default-
> constructed value when it didn't exist.
 
No worries; I applied what you mentioned prima facie, then realized, maybe map was the intention, not set.
 
 
> > Thanks for the feedback.
 
> > Best regards,
 
> > Michael Powell
 
Thanks again for the thoughtful response.
 
Cheers,
 
Michael Powell
Michael Powell <mwpowellhtx@gmail.com>: Jan 14 08:06AM -0800

On Monday, January 14, 2019 at 8:35:32 AM UTC-5, Öö Tiib wrote:
> | strings used as names, does not require that name strings
> | be unique, and does not assign any significance to the
> | ordering of name/value pairs.
 
Fair enough. I've actually read further that "uniqueness" is more of an implementation detail, but the spec itself does not restrict that aspect.
 
> with a map and would throw on multiple members with
> same name. One should use array member instead of
> multiple members with same name.
 
^ Ditto.
 
> > I think you probably meant std::map, or at least std::unordered_map. That would be a closer implementation detail to the object member associative array.
 
> Yes, my mistake, meant std::unordered_map.
 
No worries.
 
Cheers,
 
Michael Powell
Michael Powell <mwpowellhtx@gmail.com>: Jan 14 09:40AM -0800

On Monday, January 14, 2019 at 11:06:11 AM UTC-5, Michael Powell wrote:
 
One thing I am finding with the types being so raw and "closer to the metal", so to speak, is just now natural it feels to build out JSON examples, especially for the variants, their automatic conversions, etc.
 
For instance:
 
struct value_t : boost::variant<
null_t
, boolean_t
, str_t
, floating_point_number_t
, integer_number_t
, std::map<str_t, value_t>
, std::vector<value_t>
> {
 
using object_type = std::map<str_t, value_t>;
using member_type = std::pair<str_t, value_t>;
using array_type = std::vector<value_t>;
 
using base_type = boost::variant<
null_t
, boolean_t
, str_t
, floating_point_number_t
, integer_number_t
, object_type
, array_type
>;
// ...
};
using object_t = value_t::object_type;
using member_t = value_t::member_type;
using array_t = value_t::array_type;
 
Some example snippets, all of which auto-magically convert to the value_t, plus with the advent of initializer lists and so forth, just feels very natural at a C++ language level IMO:
 
null_value
// Yes, I could support the language level bool, true, false, but for parsing purposes I chose this for the time being.
boolean_true
boolean_false
array_t{}
array_t{ null_value, null_value }
array_t{ boolean_false, boolean_true }
object_t{}
 
These are just one level distilled from my unit tests, and I could extend that out any number of levels.
 
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: