aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rw-r--r--README3
-rw-r--r--boost/README2
-rw-r--r--boost/boost-vc10.vcxproj2
-rw-r--r--c++11/README68
-rw-r--r--c++11/database.hxx92
-rw-r--r--c++11/driver.cxx207
-rw-r--r--c++11/employee.hxx182
-rw-r--r--c++11/makefile135
-rw-r--r--configure.ac4
-rw-r--r--m4/c++11.m438
-rw-r--r--makefile22
-rw-r--r--qt/qt-vc10.vcxproj2
-rw-r--r--template/Makefile.am4
-rw-r--r--template/template-vc10.vcxproj2
15 files changed, 758 insertions, 9 deletions
diff --git a/Makefile.am b/Makefile.am
index abc87b1..764f277 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,6 +8,10 @@ if HAVE_TR1_MEMORY
SUBDIRS += __path__(tr1_dirs)
endif
+if HAVE_CXX11
+SUBDIRS += __path__(cxx11_dirs)
+endif
+
if ODB_EXAMPLES_BOOST
SUBDIRS += __path__(boost_dirs)
endif
diff --git a/README b/README
index 61f8818..1ed8cab 100644
--- a/README
+++ b/README
@@ -47,6 +47,9 @@ view
optimistic
Shows how to use optimistic concurrency in ODB.
+c++11
+ Shows how to use ODB with C++11.
+
boost
Shows how to persist objects that use Boost smart pointers, containers,
and value types with the help of the Boost profile library (libodb-boost).
diff --git a/boost/README b/boost/README
index 5a95ac8..8e9f18f 100644
--- a/boost/README
+++ b/boost/README
@@ -11,7 +11,7 @@ employee.hxx
establish a bidirectional employee-employer relationship. We also use
the boost::gregorian::date type to store the employee's date of birth
and the boost::unordered_set container to keep track of the employee's
- email addresses Finally, we use boost::optional for the optional middle
+ email addresses. Finally, we use boost::optional for the optional middle
name. If the middle name is not present, it will be represented in the
database as a NULL value.
diff --git a/boost/boost-vc10.vcxproj b/boost/boost-vc10.vcxproj
index f3f8dcd..e7ea41f 100644
--- a/boost/boost-vc10.vcxproj
+++ b/boost/boost-vc10.vcxproj
@@ -154,7 +154,7 @@
__custom_build_entry__(
__path__(odb_header_stem).hxx,
odb __path__(odb_header_stem).hxx,
-odb.exe __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options), @database@, __value__(database)))) __path__(odb_header_stem).hxx,
+odb.exe --std c++11 __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options), @database@, __value__(database)))) __path__(odb_header_stem).hxx,
__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx)
</ItemGroup>
<ItemGroup>
diff --git a/c++11/README b/c++11/README
new file mode 100644
index 0000000..86c0efe
--- /dev/null
+++ b/c++11/README
@@ -0,0 +1,68 @@
+This example shows how to use ODB with C++11. In particular, this example
+examines ODB support for the new std::unique_ptr and std::shared_ptr smart
+pointers and their lazy variants as well as the unordered containers. It
+also shows how to use new C++11 features such as the range-based for-loop
+when working with persistent objects and handling query results.
+
+The example consists of the following files:
+
+employee.hxx
+ Header file defining the 'employee', 'employer', and 'pension_fund'
+ persistent classes. We use the standard std::shared_ptr/weak_ptr smart
+ pointers as well as their lazy versions provided by ODB to establish a
+ bidirectional employee-employer relationship. Because we don't share the
+ 'pension_fund' objects, we use std::unique_ptr as an object pointer for
+ this persistent class. We also use the std::unordered_set container to
+ keep track of the employee's email addresses.
+
+employee-odb.hxx
+employee-odb.ixx
+employee-odb.cxx
+employee.sql
+ The first three files contain the database support code and the last file
+ contains the database schema for the employee.hxx header.
+
+ These files are generated by the ODB compiler from employee.hxx using the
+ following command line:
+
+ odb -d <database> -std c++11 --generate-schema --generate-query employee.hxx
+
+ Where <database> stands for the database system we are using, for example,
+ 'mysql'.
+
+ The -std c++11 option is used to instruct the ODB compiler to compile in
+ the C++11 mode.
+
+database.hxx
+ Contains the create_database() function which instantiates the concrete
+ database class corresponding to the database system we are using. Unlike
+ other examples, here we use std::unique_ptr instead of std::auto_ptr to
+ return the created database.
+
+driver.cxx
+ Driver for the example. It includes the employee.hxx and employee-odb.hxx
+ headers to gain access to the persistent classes and their database support
+ code. It also includes database.hxx for the create_database() function
+ declaration.
+
+ In main() the driver first calls create_database() to obtain the database
+ instance. It then creates a number of 'employee', 'employer', and
+ 'pension_fund' objects and persists them in the database. Then the driver
+ loads and prints some information about various objects and their
+ relationships. Finally, the driver performs a database query and iterates
+ over the result printing basic information about the returned objects.
+
+To run the example we may first need to create the database schema (for some
+database systems, such as SQLite, the schema is embedded into the generated
+code which makes this step unnecessary). Using MySQL as an example, this
+can be achieved with the following command:
+
+mysql --user=odb_test --database=odb_test < employee.sql
+
+Here we use 'odb_test' as the database login and also 'odb_test' as the
+database name.
+
+Once the database schema is ready, we can run the example (using MySQL as
+the database):
+
+./driver --user odb_test --database odb_test
diff --git a/c++11/database.hxx b/c++11/database.hxx
new file mode 100644
index 0000000..b362e8e
--- /dev/null
+++ b/c++11/database.hxx
@@ -0,0 +1,92 @@
+// file : c++11/database.hxx
+// copyright : not copyrighted - public domain
+
+//
+// Create concrete database instance based on the DATABASE_* macros.
+//
+
+#ifndef DATABASE_HXX
+#define DATABASE_HXX
+
+#include <string>
+#include <memory> // std::unique_ptr
+#include <cstdlib> // std::exit
+#include <iostream>
+
+#include <odb/database.hxx>
+
+#if defined(DATABASE_MYSQL)
+# include <odb/mysql/database.hxx>
+#elif defined(DATABASE_SQLITE)
+# include <odb/connection.hxx>
+# include <odb/transaction.hxx>
+# include <odb/schema-catalog.hxx>
+# include <odb/sqlite/database.hxx>
+#elif defined(DATABASE_PGSQL)
+# include <odb/pgsql/database.hxx>
+#elif defined(DATABASE_ORACLE)
+# include <odb/oracle/database.hxx>
+#elif defined(DATABASE_MSSQL)
+# include <odb/mssql/database.hxx>
+#endif
+
+inline std::unique_ptr<odb::database>
+create_database (int& argc, char* argv[])
+{
+ using namespace std;
+ using namespace odb::core;
+
+ if (argc > 1 && argv[1] == string ("--help"))
+ {
+ cerr << "Usage: " << argv[0] << " [options]" << endl
+ << "Options:" << endl;
+
+#if defined(DATABASE_MYSQL)
+ odb::mysql::database::print_usage (cerr);
+#elif defined(DATABASE_SQLITE)
+ odb::sqlite::database::print_usage (cerr);
+#elif defined(DATABASE_PGSQL)
+ odb::pgsql::database::print_usage (cerr);
+#elif defined(DATABASE_ORACLE)
+ odb::oracle::database::print_usage (cerr);
+#elif defined(DATABASE_MSSQL)
+ odb::mssql::database::print_usage (cerr);
+#endif
+
+ exit (0);
+ }
+
+#if defined(DATABASE_MYSQL)
+ unique_ptr<database> db (new odb::mysql::database (argc, argv));
+#elif defined(DATABASE_SQLITE)
+ unique_ptr<database> db (
+ new odb::sqlite::database (
+ argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE));
+
+ // Create the database schema. Due to bugs in SQLite foreign key
+ // support for DDL statements, we need to temporarily disable
+ // foreign keys.
+ //
+ {
+ connection_ptr c (db->connection ());
+
+ c->execute ("PRAGMA foreign_keys=OFF");
+
+ transaction t (c->begin ());
+ schema_catalog::create_schema (*db);
+ t.commit ();
+
+ c->execute ("PRAGMA foreign_keys=ON");
+ }
+#elif defined(DATABASE_PGSQL)
+ unique_ptr<database> db (new odb::pgsql::database (argc, argv));
+#elif defined(DATABASE_ORACLE)
+ unique_ptr<database> db (new odb::oracle::database (argc, argv));
+#elif defined(DATABASE_MSSQL)
+ unique_ptr<database> db (new odb::mssql::database (argc, argv));
+#endif
+
+ return db;
+}
+
+#endif // DATABASE_HXX
diff --git a/c++11/driver.cxx b/c++11/driver.cxx
new file mode 100644
index 0000000..68793b1
--- /dev/null
+++ b/c++11/driver.cxx
@@ -0,0 +1,207 @@
+// file : c++11/driver.cxx
+// copyright : not copyrighted - public domain
+
+#include <memory> // std::unique_ptr
+#include <iostream>
+
+#include <odb/database.hxx>
+#include <odb/session.hxx>
+#include <odb/transaction.hxx>
+
+#include "database.hxx" // create_database
+
+#include "employee.hxx"
+#include "employee-odb.hxx"
+
+using namespace std;
+using namespace odb::core;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ unique_ptr<database> db (create_database (argc, argv));
+
+ // Create a few persistent objects.
+ //
+ {
+ pension_fund bf ("Bright Future");
+
+ // Simple Tech Ltd.
+ //
+ {
+ shared_ptr<employer> er (new employer ("Simple Tech Ltd"));
+
+ shared_ptr<employee> john (new employee ("John", "Doe", er));
+ shared_ptr<employee> jane (new employee ("Jane", "Doe", er));
+
+ john->emails ().insert ("john_d@example.com");
+ john->emails ().insert ("john.doe@example.com");
+
+ jane->emails ().insert ("jane_d@example.com");
+ jane->emails ().insert ("jane.doe@example.com");
+
+ // Set the inverse side of the employee-employer relationship.
+ //
+ er->employees ().push_back (john);
+ er->employees ().push_back (jane);
+
+ transaction t (db->begin ());
+
+ db->persist (er);
+
+ db->persist (john);
+ db->persist (jane);
+
+ t.commit ();
+
+ bf.members ().push_back (lazy_shared_ptr<employee> (*db, john));
+ }
+
+ // Complex Systems Inc.
+ //
+ {
+ shared_ptr<employer> er (new employer ("Complex Systems Inc"));
+
+ shared_ptr<employee> john (new employee ("John", "Smith", er));
+ shared_ptr<employee> jane (new employee ("Jane", "Smith", er));
+
+ john->emails ().insert ("john_s@example.com");
+ john->emails ().insert ("john.smith@example.com");
+
+ jane->emails ().insert ("jane_s@example.com");
+ jane->emails ().insert ("jane.smith@example.com");
+
+ // Set the inverse side of the employee-employer relationship.
+ //
+ er->employees ().push_back (john);
+ er->employees ().push_back (jane);
+
+ transaction t (db->begin ());
+
+ db->persist (er);
+
+ db->persist (john);
+ db->persist (jane);
+
+ t.commit ();
+
+ bf.members ().push_back (lazy_shared_ptr<employee> (*db, jane));
+ }
+
+ transaction t (db->begin ());
+ db->persist (bf);
+ t.commit ();
+ }
+
+ // Load the Bright Future pension fund and print its members.
+ //
+ {
+ session s;
+ transaction t (db->begin ());
+
+ unique_ptr<pension_fund> bf (db->load<pension_fund> ("Bright Future"));
+
+ for (auto i (bf->members ().begin ()); i != bf->members ().end (); ++i)
+ {
+ lazy_shared_ptr<employee>& p (*i);
+ p.load ();
+
+ cout << p->first () << ' ' << p->last () << ", " <<
+ p->employer ()->name () << endl;
+ }
+
+ // Alternative implementation using range-based for-loop.
+ //
+ /*
+ for (lazy_shared_ptr<employee>& p: bf->members ())
+ {
+ p.load ();
+ cout << p->first () << ' ' << p->last () << ", " <<
+ p->employer ()->name () << endl;
+ }
+ */
+
+ cout << endl;
+ }
+
+ // Load Simple Tech Ltd and print its employees.
+ //
+ {
+ session s;
+ transaction t (db->begin ());
+
+ shared_ptr<employer> st (db->load<employer> ("Simple Tech Ltd"));
+
+ for (auto i (st->employees ().begin ());
+ i != st->employees ().end ();
+ ++i)
+ {
+ lazy_weak_ptr<employee>& lwp (*i);
+ shared_ptr<employee> p (lwp.load ()); // Load and lock.
+
+ cout << p->first () << ' ' << p->last () << endl
+ << " employer: " << p->employer ()->name () << endl;
+
+ for (auto j (p->emails ().begin ()); j != p->emails ().end (); ++j)
+ {
+ cout << " email: " << *j << endl;
+ }
+
+ cout << endl;
+ }
+
+ // Alternative implementation using range-based for-loop.
+ //
+ /*
+ for (lazy_weak_ptr<employee>& lwp: st->employees ())
+ {
+ shared_ptr<employee> p (lwp.load ()); // Load and lock.
+
+ cout << p->first () << ' ' << p->last () << endl
+ << " employer: " << p->employer ()->name () << endl;
+
+ for (const string& e: p->emails ())
+ cout << " email: " << e << endl;
+
+ cout << endl;
+ }
+ */
+
+ t.commit ();
+ }
+
+
+ // Search for Complex Systems Inc employees with the John first name.
+ //
+ {
+ typedef odb::query<employee> query;
+ typedef odb::result<employee> result;
+
+ session s;
+ transaction t (db->begin ());
+
+ result r (db->query<employee> (
+ query::employer->name == "Complex Systems Inc" &&
+ query::first == "John"));
+
+ for (auto i (r.begin ()); i != r.end (); ++i)
+ cout << i->first () << ' ' << i->last () << endl;
+
+ // Alternative implementation using range-based for-loop.
+ //
+ /*
+ for (const employee& e: r)
+ cout << e.first () << ' ' << e.last () << endl;
+ */
+
+ t.commit ();
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/c++11/employee.hxx b/c++11/employee.hxx
new file mode 100644
index 0000000..3750ca0
--- /dev/null
+++ b/c++11/employee.hxx
@@ -0,0 +1,182 @@
+// file : boost/employee.hxx
+// copyright : not copyrighted - public domain
+
+#ifndef EMPLOYEE_HXX
+#define EMPLOYEE_HXX
+
+#include <string>
+#include <memory> // std::unique_ptr, std::shared_ptr
+#include <vector>
+#include <unordered_set>
+
+#include <odb/core.hxx>
+#include <odb/lazy-ptr.hxx> // odb::lazy_shared_ptr, odb::lazy_weak_ptr
+
+// Forward declarations.
+//
+class employer;
+class employee;
+
+#pragma db object pointer(std::shared_ptr)
+class employer
+{
+public:
+ employer (const std::string& name)
+ : name_ (name)
+ {
+ }
+
+ const std::string&
+ name () const
+ {
+ return name_;
+ }
+
+ // Employees of this employer.
+ //
+ typedef std::vector<odb::lazy_weak_ptr<employee>> employees_type;
+
+ const employees_type&
+ employees () const
+ {
+ return employees_;
+ }
+
+ employees_type&
+ employees ()
+ {
+ return employees_;
+ }
+
+private:
+ friend class odb::access;
+
+ employer () {}
+
+ #pragma db id
+ std::string name_;
+
+ #pragma db value_not_null inverse(employer_)
+ employees_type employees_;
+};
+
+#pragma db object pointer(std::shared_ptr)
+class employee
+{
+public:
+ typedef ::employer employer_type;
+
+ employee (const std::string& first,
+ const std::string& last,
+ std::shared_ptr<employer_type> employer)
+ : first_ (first), last_ (last), employer_ (employer)
+ {
+ }
+
+ // Name.
+ //
+ const std::string&
+ first () const
+ {
+ return first_;
+ }
+
+ const std::string&
+ last () const
+ {
+ return last_;
+ }
+
+ // Emails.
+ //
+ typedef std::unordered_set<std::string> emails_type;
+
+ const emails_type&
+ emails () const
+ {
+ return emails_;
+ }
+
+ emails_type&
+ emails ()
+ {
+ return emails_;
+ }
+
+ // Employer.
+ //
+ std::shared_ptr<employer_type>
+ employer () const
+ {
+ return employer_;
+ }
+
+ void
+ employer (std::shared_ptr<employer_type> employer)
+ {
+ employer_ = employer;
+ }
+
+private:
+ friend class odb::access;
+
+ employee () {}
+
+ #pragma db id auto
+ unsigned long id_;
+
+ std::string first_;
+ std::string last_;
+ emails_type emails_;
+
+ #pragma db not_null
+ std::shared_ptr<employer_type> employer_;
+};
+
+// std::unique_ptr is a good choice for an object pointer if we are
+// not planning to do any sharing.
+//
+#pragma db object pointer(std::unique_ptr)
+class pension_fund
+{
+public:
+ pension_fund (const std::string& name)
+ : name_ (name)
+ {
+ }
+
+ const std::string&
+ name () const
+ {
+ return name_;
+ }
+
+ // Members of this fund.
+ //
+ typedef std::vector<odb::lazy_shared_ptr<employee>> members_type;
+
+ const members_type&
+ members () const
+ {
+ return members_;
+ }
+
+ members_type&
+ members ()
+ {
+ return members_;
+ }
+
+private:
+ friend class odb::access;
+
+ pension_fund () {}
+
+ #pragma db id
+ std::string name_;
+
+ #pragma db value_not_null
+ members_type members_;
+};
+
+#endif // EMPLOYEE_HXX
diff --git a/c++11/makefile b/c++11/makefile
new file mode 100644
index 0000000..ae5ff89
--- /dev/null
+++ b/c++11/makefile
@@ -0,0 +1,135 @@
+# file : c++11/makefile
+# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+# license : GNU GPL v2; see accompanying LICENSE file
+
+include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make
+
+cxx_tun := driver.cxx
+odb_hdr := employee.hxx
+cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o))
+cxx_od := $(cxx_obj:.o=.o.d)
+
+driver := $(out_base)/driver
+dist := $(out_base)/.dist
+test := $(out_base)/.test
+clean := $(out_base)/.clean
+
+# Import.
+#
+$(call import,\
+ $(scf_root)/import/odb/stub.make,\
+ odb: odb,odb-rules: odb_rules)
+
+$(call import,\
+ $(scf_root)/import/libodb/stub.make,\
+ l: odb.l,cpp-options: odb.l.cpp-options)
+
+$(call import,\
+ $(scf_root)/import/libodb-boost/stub.make,\
+ l: odb_boost.l,cpp-options: odb_boost.l.cpp-options)
+
+$(call import,\
+ $(scf_root)/import/libboost/header-only/stub.make,\
+ cpp-options: boost.l.cpp-options)
+
+$(call import,\
+ $(scf_root)/import/libboost/date-time/stub.make,\
+ l: boost_date_time.l)
+
+ifdef db_id
+$(call import,\
+ $(scf_root)/import/libodb-$(db_id)/stub.make,\
+ l: odb_db.l,cpp-options: odb_db.l.cpp-options)
+endif
+
+ifeq ($(odb_db.l.cpp-options),)
+odb_db.l.cpp-options := $(out_base)/.unbuildable
+endif
+
+# Build.
+#
+$(driver): $(cxx_obj) $(odb_db.l) $(odb_boost.l) $(odb.l) $(boost_date_time.l)
+$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro)
+$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_boost.l.cpp-options) \
+$(odb_db.l.cpp-options) $(boost.l.cpp-options)
+
+genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql)
+gen := $(addprefix $(out_base)/,$(genf))
+
+$(gen): $(odb)
+$(gen): odb := $(odb)
+$(gen) $(dist): export odb_options += --database $(db_id) \
+--generate-query --generate-schema --table-prefix boost_
+$(gen): cpp_options := -I$(src_base)
+$(gen): $(odb.l.cpp-options) $(odb_boost.l.cpp-options) $(boost.l.cpp-options)
+
+# Don't generate dependencies unless we are in the C++11 mode.
+#
+$(call include,$(bld_root)/cxx/standard.make) # cxx_standard
+
+ifeq ($(cxx_standard),c++11)
+$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
+endif
+
+# Alias for default target.
+#
+$(out_base)/: $(driver)
+
+# Dist
+#
+name := $(subst /,-,$(subst $(src_root)/,,$(src_base)))
+
+$(dist): db_id := @database@
+$(dist): sources := $(cxx_tun)
+$(dist): headers := $(odb_hdr)
+$(dist): export name := $(name)
+$(dist): export odb_header_stem := $(basename $(odb_hdr))
+$(dist): export extra_dist := README $(call vc10projs,$(name))
+$(dist):
+ $(call dist-data,$(sources) $(headers) README database.hxx)
+ $(call meta-automake,../template/Makefile.am)
+ $(call meta-vc10projs,../template/template,$(name))
+
+# Test.
+#
+$(test): header := $(odb_hdr)
+$(test): $(driver)
+ $(call schema)
+ $(call message,test $<,$< --options-file $(dcf_root)/db.options)
+
+# Clean.
+#
+$(clean): \
+ $(driver).o.clean \
+ $(addsuffix .cxx.clean,$(cxx_obj)) \
+ $(addsuffix .cxx.clean,$(cxx_od)) \
+ $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean))
+
+# Generated .gitignore.
+#
+ifeq ($(out_base),$(src_base))
+$(driver): | $(out_base)/.gitignore
+
+$(out_base)/.gitignore: files := driver $(genf)
+$(clean): $(out_base)/.gitignore.clean
+
+$(call include,$(bld_root)/git/gitignore.make)
+endif
+
+# How to.
+#
+$(call include,$(bld_root)/dist.make)
+$(call include,$(bld_root)/meta/vc10sln.make)
+$(call include,$(bld_root)/meta/vc10proj.make)
+$(call include,$(bld_root)/meta/automake.make)
+
+$(call include,$(bld_root)/cxx/standard.make) # cxx_standard
+ifdef cxx_standard
+$(gen): odb_options += --std $(cxx_standard)
+$(call include,$(odb_rules))
+endif
+
+$(call include,$(bld_root)/cxx/cxx-d.make)
+$(call include,$(bld_root)/cxx/cxx-o.make)
+$(call include,$(bld_root)/cxx/o-e.make)
+
diff --git a/configure.ac b/configure.ac
index 2c4bec4..1496b60 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,6 +29,10 @@ THREADS
AM_CONDITIONAL([ODB_EXAMPLES_THREADS], [test x$threads != xnone])
+# Check for C++11.
+#
+CXX11([HAVE_CXX11], [Compiling in the C++11 mode.])
+
# Check for the ODB compiler.
#
ODB_COMPILER([], [AC_MSG_ERROR([odb compiler is not found; consider setting ODB variable or using --with-odb=DIR])])
diff --git a/m4/c++11.m4 b/m4/c++11.m4
new file mode 100644
index 0000000..774f20d
--- /dev/null
+++ b/m4/c++11.m4
@@ -0,0 +1,38 @@
+dnl file : m4/cxx11.m4
+dnl copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC
+dnl license : GNU GPL v2; see accompanying LICENSE file
+dnl
+dnl CXX11(MACRO, DESCRIPTION)
+dnl
+dnl Check if we are compiling in the C++11 mode. If we are, define MACRO as
+dnl both a macro and conditional as well as set the cxx11 variable to 'yes'.
+dnl
+AC_DEFUN([CXX11],
+[
+cxx11=no
+
+AC_MSG_CHECKING([whether we are in C++11 mode])
+
+CXX_LIBTOOL_LINK_IFELSE(
+AC_LANG_SOURCE([[
+#include <memory>
+
+int
+main ()
+{
+ std::shared_ptr<int> p (new int (10));
+ *p = 11;
+}
+]]),
+[cxx11=yes])
+
+if test x"$cxx11" = xyes; then
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([$1], [1], [$2])
+else
+ AC_MSG_RESULT([no])
+fi
+
+AM_CONDITIONAL([$1], [test x$cxx11 = xyes])
+
+])dnl
diff --git a/makefile b/makefile
index 1168586..f9c9121 100644
--- a/makefile
+++ b/makefile
@@ -15,22 +15,34 @@ optimistic \
schema/embedded
tr1_dirs := relationship inverse schema/custom view
+cxx11_dirs := c++11
boost_dirs := boost
qt_dirs := qt
-dist_dirs := $(dirs) $(tr1_dirs) $(boost_dirs) $(qt_dirs)
-all_dirs := $(dirs) $(tr1_dirs) $(boost_dirs) $(qt_dirs) template
-
default := $(out_base)/
dist := $(out_base)/.dist
test := $(out_base)/.test
clean := $(out_base)/.clean
-$(default): $(addprefix $(out_base)/,$(addsuffix /,$(all_dirs)))
+$(default):
+$(call include,$(bld_root)/cxx/standard.make) # cxx_standard
+
+dist_dirs := $(dirs) $(tr1_dirs) $(cxx11_dirs) $(boost_dirs) $(qt_dirs)
+all_dirs := $(dirs) $(tr1_dirs) $(cxx11_dirs) $(boost_dirs) $(qt_dirs) \
+template
+
+build_dirs := $(dirs) $(tr1_dirs) $(boost_dirs) $(qt_dirs) template
+
+ifeq ($(cxx_standard),c++11)
+build_dirs += c++11
+endif
+
+$(default): $(addprefix $(out_base)/,$(addsuffix /,$(build_dirs)))
$(dist): name := examples
$(dist): export dirs := $(dirs)
$(dist): export tr1_dirs := $(tr1_dirs)
+$(dist): export cxx11_dirs := $(cxx11_dirs)
$(dist): export boost_dirs := $(boost_dirs)
$(dist): export qt_dirs := $(qt_dirs)
$(dist): data_dist := GPLv2 LICENSE README NEWS INSTALL version tester.bat \
@@ -52,7 +64,7 @@ $(dist): $(addprefix $(out_base)/,$(addsuffix /.dist,$(dist_dirs)))
$(call meta-vc10slns,$(name))
$(call meta-vctest,$(name)-mysql-vc10.sln,test.bat)
-$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(all_dirs)))
+$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(build_dirs)))
$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(all_dirs)))
$(call include,$(bld_root)/dist.make)
diff --git a/qt/qt-vc10.vcxproj b/qt/qt-vc10.vcxproj
index 2c14259..308db1c 100644
--- a/qt/qt-vc10.vcxproj
+++ b/qt/qt-vc10.vcxproj
@@ -154,7 +154,7 @@
__custom_build_entry__(
__path__(odb_header_stem).hxx,
odb __path__(odb_header_stem).hxx,
-odb.exe __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options), @database@, __value__(database)))) __path__(odb_header_stem).hxx,
+odb.exe --std c++11 __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options), @database@, __value__(database)))) __path__(odb_header_stem).hxx,
__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx)
</ItemGroup>
<ItemGroup>
diff --git a/template/Makefile.am b/template/Makefile.am
index d59aa5b..f39fbad 100644
--- a/template/Makefile.am
+++ b/template/Makefile.am
@@ -42,5 +42,9 @@ ODB = @ODB@
ODBFLAGS = @ODBFLAGS@
ODBCPPFLAGS = @ODBCPPFLAGS@
+if HAVE_CXX11
+ODBFLAGS += --std c++11
+endif
+
__path__(odb_header_stem)-odb.hxx: __path__(odb_header_stem).hxx
$(ODB) $(ODBCPPFLAGS) $(CPPFLAGS) $(ODBFLAGS) __value__(odb_options) $<
diff --git a/template/template-vc10.vcxproj b/template/template-vc10.vcxproj
index 817b728..c595f1b 100644
--- a/template/template-vc10.vcxproj
+++ b/template/template-vc10.vcxproj
@@ -154,7 +154,7 @@
__custom_build_entry__(
__path__(odb_header_stem).hxx,
odb __path__(odb_header_stem).hxx,
-odb.exe __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options), @database@, __value__(database)))) __path__(odb_header_stem).hxx,
+odb.exe --std c++11 __xml__(__shell_quotes__(m4_patsubst(__value__(odb_options), @database@, __value__(database)))) __path__(odb_header_stem).hxx,
__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx)
</ItemGroup>
<ItemGroup>