fusion pair issue?

Patrick Welche <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <20170327153413.GC19812@quark>
Given the trivial working attached code, I do the following:

--- works.cpp	2017-03-27 17:25:13.008492450 +0200
+++ fails.cpp	2016-06-14 13:17:12.683679158 +0200
@@ -2,16 +2,17 @@
 
 #include <boost/spirit/home/x3.hpp>
 #include <boost/fusion/include/adapt_struct.hpp>
+#include <boost/fusion/include/std_pair.hpp>
 
 namespace x3 = boost::spirit::x3;
 
 struct result
 {
-	std::string first, second;
+	std::pair<std::string, std::string> both;
 };
 
 BOOST_FUSION_ADAPT_STRUCT(result,
-	first, second
+	both
 )
 
 int main()
@@ -27,8 +28,8 @@
 		std::cout << "Bit left over at the end: "
 		          << std::string(iter, end) << std::endl;
 	else
-		std::cout << "found: " << res.first << ' '
-		                       << res.second << std::endl;
+		std::cout << "found: " << res.both.first << ' '
+		                       << res.both.second << std::endl;
 
 	return 0;
 }


and get a compiler error. What have I forgotten to change?

(Hoping to use the automatic semantic action feature of x3. I'm sure I
could write a lot more code and have it work, but I don't see why a priori
the above isn't sufficient...)

Cheers,

Patrick

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general
works.cpp (text/plain, 755 B)
#define BOOST_SPIRIT_X3_DEBUG

#include <boost/spirit/home/x3.hpp>
#include <boost/fusion/include/adapt_struct.hpp>

namespace x3 = boost::spirit::x3;

struct result
{
	std::string first, second;
};

BOOST_FUSION_ADAPT_STRUCT(result,
	first, second
)

int main()
{
	std::string buf("one two");
	std::string::const_iterator iter = buf.begin();
	std::string::const_iterator end = buf.end();
	result res;
	bool ok = x3::parse(iter, end, +x3::alnum >> ' ' >> +x3::alnum, res);
	if (!ok)
		std::cout << "Parsing failed\n";
	else if (iter != end)
		std::cout << "Bit left over at the end: "
		          << std::string(iter, end) << std::endl;
	else
		std::cout << "found: " << res.first << ' '
		                       << res.second << std::endl;

	return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.