Repository: Kitware/kwiver (language: python)

Issue:
Replace kwiver::vital::optional with std::optional
- Replace kwiver::vital::optional with std::optional, introduced in C++17
- Replace kwiver::vital::nullopt with std::nullopt, introduced in C++17


Discussion / hints:

Fix patch:
diff --git a/arrows/ffmpeg/ffmpeg_video_input.cxx b/arrows/ffmpeg/ffmpeg_video_input.cxx
index 7f582493f7..8aed9bc154 100644
--- a/arrows/ffmpeg/ffmpeg_video_input.cxx
+++ b/arrows/ffmpeg/ffmpeg_video_input.cxx
@@ -29,7 +29,6 @@
 
 #include <vital/util/tokenize.h>
 
-#include <vital/optional.h>
 #include <vital/vital_config.h>
 
 #include <kwiversys/SystemTools.hxx>
@@ -50,6 +49,7 @@ extern "C" {
 #include <list>
 #include <memory>
 #include <mutex>
+#include <optional>
 #include <sstream>
 #include <vector>
 
@@ -75,7 +75,7 @@ struct ffmpeg_klv_stream
 
   void send_packet( AVPacket* packet );
 
-  void advance( kv::optional< uint64_t > backup_timestamp,
+  void advance( std::optional< uint64_t > backup_timestamp,
                 int64_t max_pts, int64_t max_pos );
 
   void reset();
@@ -159,7 +159,7 @@ ::send_packet( AVPacket* packet )
 void
 ffmpeg_klv_stream
 ::advance(
-  kv::optional< uint64_t > backup_timestamp, int64_t max_pts, int64_t max_pos )
+  std::optional< uint64_t > backup_timestamp, int64_t max_pts, int64_t max_pos )
 {
   packets.clear();
 
@@ -287,7 +287,7 @@ class ffmpeg_video_input::priv
     kv::image_container_sptr image;
     ffmpeg_video_raw_image_sptr raw_image;
 
-    kv::optional< kv::metadata_vector > metadata;
+    std::optional< kv::metadata_vector > metadata;
     ffmpeg_video_raw_metadata_sptr raw_metadata;
 
     bool is_draining;
@@ -333,7 +333,7 @@ class ffmpeg_video_input::priv
     std::list< ffmpeg_klv_stream > klv_streams;
     kv::metadata_map_sptr all_metadata;
 
-    kv::optional< frame_state > frame;
+    std::optional< frame_state > frame;
 
     bool at_eof;
   };
@@ -353,7 +353,7 @@ class ffmpeg_video_input::priv
   bool cuda_enabled;
   int cuda_device_index;
 
-  kv::optional< open_video_state > video;
+  std::optional< open_video_state > video;
 
   priv( ffmpeg_video_input& parent );
   ~priv();
diff --git a/arrows/ffmpeg/ffmpeg_video_output.cxx b/arrows/ffmpeg/ffmpeg_video_output.cxx
index 17c33df477..bf5e1c4940 100644
--- a/arrows/ffmpeg/ffmpeg_video_output.cxx
+++ b/arrows/ffmpeg/ffmpeg_video_output.cxx
@@ -11,8 +11,6 @@
 #include "arrows/ffmpeg/ffmpeg_video_raw_image.h"
 #include "arrows/ffmpeg/ffmpeg_video_settings.h"
 
-#include <vital/optional.h>
-
 extern "C" {
 #include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
@@ -20,6 +18,8 @@ extern "C" {
 #include <libswscale/swscale.h>
 }
 
+#include <optional>
+
 namespace kv = kwiver::vital;
 
 namespace kwiver {
@@ -94,7 +94,7 @@ class ffmpeg_video_output::impl
   bool cuda_enabled;
   int cuda_device_index;
 
-  kv::optional< open_video_state > video;
+  std::optional< open_video_state > video;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/arrows/klv/klv_0601.h b/arrows/klv/klv_0601.h
index 5a46c40c5e..41520a2bca 100644
--- a/arrows/klv/klv_0601.h
+++ b/arrows/klv/klv_0601.h
@@ -18,8 +18,7 @@
 #include "klv_util.h"
 #include "klv_series.h"
 
-#include "vital/optional.h"
-
+#include <optional>
 #include <ostream>
 
 namespace kwiver {
@@ -351,7 +350,7 @@ struct KWIVER_ALGO_KLV_EXPORT klv_0601_image_horizon_pixel_pack
   uint8_t y0;
   uint8_t x1;
   uint8_t y1;
-  kwiver::vital::optional< klv_0601_image_horizon_locations > locations;
+  std::optional< klv_0601_image_horizon_locations > locations;
 };
 
 // ----------------------------------------------------------------------------
@@ -445,7 +444,7 @@ struct KWIVER_ALGO_KLV_EXPORT klv_0601_control_command
 {
   uint16_t id;
   std::string string;
-  vital::optional< uint64_t > timestamp;
+  std::optional< uint64_t > timestamp;
 };
 
 // ----------------------------------------------------------------------------
@@ -528,9 +527,9 @@ class KWIVER_ALGO_KLV_EXPORT klv_0601_frame_rate_format
 struct klv_0601_country_codes
 {
   klv_0102_country_coding_method coding_method;
-  kwiver::vital::optional< std::string > overflight_country;
-  kwiver::vital::optional< std::string > operator_country;
-  kwiver::vital::optional< std::string > country_of_manufacture;
+  std::optional< std::string > overflight_country;
+  std::optional< std::string > operator_country;
+  std::optional< std::string > country_of_manufacture;
 };
 
 // ----------------------------------------------------------------------------
@@ -570,7 +569,7 @@ struct klv_0601_location_dlp
 {
   double latitude;
   double longitude;
-  kwiver::vital::optional< double > altitude;
+  std::optional< double > altitude;
 };
 
 // ----------------------------------------------------------------------------
@@ -607,8 +606,8 @@ class KWIVER_ALGO_KLV_EXPORT klv_0601_location_dlp_format
 /// Geographic location of the take-off site and recovery site.
 struct klv_0601_airbase_locations
 {
-  kwiver::vital::optional< klv_0601_location_dlp > take_off_location;
-  kwiver::vital::optional< klv_0601_location_dlp > recovery_location;
+  std::optional< klv_0601_location_dlp > take_off_location;
+  std::optional< klv_0601_location_dlp > recovery_location;
 };
 
 // ----------------------------------------------------------------------------
@@ -690,9 +689,9 @@ class KWIVER_ALGO_KLV_EXPORT klv_0601_view_domain_interval_format
 /// Relative Sensor Azimuth, Elevation and Roll Angles.
 struct klv_0601_view_domain
 {
-  kwiver::vital::optional< klv_0601_view_domain_interval > azimuth;
-  kwiver::vital::optional< klv_0601_view_domain_interval > elevation;
-  kwiver::vital::optional< klv_0601_view_domain_interval > roll;
+  std::optional< klv_0601_view_domain_interval > azimuth;
+  std::optional< klv_0601_view_domain_interval > elevation;
+  std::optional< klv_0601_view_domain_interval > roll;
 };
 
 // ----------------------------------------------------------------------------
@@ -756,8 +755,8 @@ struct klv_0601_waypoint_record
 {
   uint16_t id;
   int16_t order;
-  kwiver::vital::optional< std::set< klv_0601_waypoint_info_bit > > info;
-  kwiver::vital::optional< klv_0601_location_dlp > location;
+  std::optional< std::set< klv_0601_waypoint_info_bit > > info;
+  std::optional< klv_0601_location_dlp > location;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/arrows/klv/klv_0903_location_pack.h b/arrows/klv/klv_0903_location_pack.h
index 1fb660008e..193da879bf 100644
--- a/arrows/klv/klv_0903_location_pack.h
+++ b/arrows/klv/klv_0903_location_pack.h
@@ -14,7 +14,7 @@
 #include <arrows/klv/klv_series.h>
 #include <arrows/klv/klv_set.h>
 
-#include <vital/optional.h>
+#include <optional>
 
 namespace kwiver {
 
@@ -63,8 +63,8 @@ struct KWIVER_ALGO_KLV_EXPORT klv_0903_location_pack
   double latitude;
   double longitude;
   double altitude;
-  kwiver::vital::optional< klv_0903_sigma_pack > sigma;
-  kwiver::vital::optional< klv_0903_rho_pack > rho;
+  std::optional< klv_0903_sigma_pack > sigma;
+  std::optional< klv_0903_rho_pack > rho;
 };
 
 // ----------------------------------------------------------------------------
@@ -82,8 +82,8 @@ struct KWIVER_ALGO_KLV_EXPORT klv_0903_velocity_pack
   double east;
   double north;
   double up;
-  kwiver::vital::optional< klv_0903_sigma_pack > sigma;
-  kwiver::vital::optional< klv_0903_rho_pack > rho;
+  std::optional< klv_0903_sigma_pack > sigma;
+  std::optional< klv_0903_rho_pack > rho;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/arrows/klv/klv_1002.h b/arrows/klv/klv_1002.h
index 18c4dfe82b..ce7d524d28 100644
--- a/arrows/klv/klv_1002.h
+++ b/arrows/klv/klv_1002.h
@@ -15,7 +15,7 @@
 #include <arrows/klv/klv_util.h>
 #include <arrows/klv/kwiver_algo_klv_export.h>
 
-#include <vital/optional.h>
+#include <optional>
 
 namespace kwiver {
 
@@ -132,10 +132,10 @@ struct KWIVER_ALGO_KLV_EXPORT klv_1002_section_data_pack
   uint32_t section_x;
   uint32_t section_y;
   klv_1303_mdap< double > measurements;
-  kwiver::vital::optional< klv_1303_mdap< double > > uncertainty;
-  kwiver::vital::optional< klv_lengthy< double > > plane_x_scale;
-  kwiver::vital::optional< klv_lengthy< double > > plane_y_scale;
-  kwiver::vital::optional< klv_lengthy< double > > plane_constant;
+  std::optional< klv_1303_mdap< double > > uncertainty;
+  std::optional< klv_lengthy< double > > plane_x_scale;
+  std::optional< klv_lengthy< double > > plane_y_scale;
+  std::optional< klv_lengthy< double > > plane_constant;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/arrows/klv/klv_1010.h b/arrows/klv/klv_1010.h
index 8ac3fdc85d..476c7132f4 100644
--- a/arrows/klv/klv_1010.h
+++ b/arrows/klv/klv_1010.h
@@ -12,9 +12,8 @@
 #include <arrows/klv/klv_util.h>
 #include <arrows/klv/kwiver_algo_klv_export.h>
 
-#include <vital/optional.h>
-
 #include <bitset>
+#include <optional>
 #include <ostream>
 
 namespace kwiver {
diff --git a/arrows/klv/klv_1204.h b/arrows/klv/klv_1204.h
index 885701f007..d1feaa34d1 100644
--- a/arrows/klv/klv_1204.h
+++ b/arrows/klv/klv_1204.h
@@ -12,9 +12,8 @@
 #include <arrows/klv/klv_packet.h>
 #include <arrows/klv/klv_uuid.h>
 
-#include <vital/optional.h>
-
 #include <array>
+#include <optional>
 #include <ostream>
 
 namespace kwiver {
@@ -44,10 +43,10 @@ struct KWIVER_ALGO_KLV_EXPORT klv_1204_miis_id
   uint8_t version;
   klv_1204_device_id_type sensor_id_type;
   klv_1204_device_id_type platform_id_type;
-  kwiver::vital::optional< klv_uuid > sensor_id;
-  kwiver::vital::optional< klv_uuid > platform_id;
-  kwiver::vital::optional< klv_uuid > window_id;
-  kwiver::vital::optional< klv_uuid > minor_id;
+  std::optional< klv_uuid > sensor_id;
+  std::optional< klv_uuid > platform_id;
+  std::optional< klv_uuid > window_id;
+  std::optional< klv_uuid > minor_id;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/arrows/klv/klv_1303.h b/arrows/klv/klv_1303.h
index 8c233197cd..e979c13d2b 100644
--- a/arrows/klv/klv_1303.h
+++ b/arrows/klv/klv_1303.h
@@ -12,10 +12,10 @@
 #include <arrows/klv/klv_util.h>
 #include <arrows/klv/kwiver_algo_klv_export.h>
 
-#include <vital/optional.h>
 #include <vital/util/interval.h>
 
 #include <array>
+#include <optional>
 
 namespace kwiver {
 
@@ -59,7 +59,7 @@ struct KWIVER_ALGO_KLV_EXPORT klv_1303_mdap
   size_t element_size;
   klv_1303_apa apa;
   size_t apa_params_length;
-  kwiver::vital::optional< kwiver::vital::interval< double > > imap_params;
+  std::optional< kwiver::vital::interval< double > > imap_params;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/arrows/klv/klv_convert_vital.cxx b/arrows/klv/klv_convert_vital.cxx
index 71da99143c..e3a2d8f090 100644
--- a/arrows/klv/klv_convert_vital.cxx
+++ b/arrows/klv/klv_convert_vital.cxx
@@ -15,6 +15,7 @@
 #include <vital/types/geodesy.h>
 
 #include <iomanip>
+#include <optional>
 
 #include <cstdint>
 
@@ -88,7 +89,7 @@ assemble_geo_point( klv_value const& latitude,
 // Create a geo_point from the given lists of tags, which are queried in order
 // to enforce precedence of e.g. newer or more precise tags over deprecated or
 // less precise ones
-kv::optional< kv::geo_point >
+std::optional< kv::geo_point >
 parse_geo_point( klv_timeline const& klv_data,
                  klv_top_level_tag standard,
                  uint64_t timestamp,
@@ -107,7 +108,7 @@ parse_geo_point( klv_timeline const& klv_data,
   }
   if( !latitude.valid() )
   {
-    return kv::nullopt;
+    return std::nullopt;
   }
 
   klv_value longitude;
@@ -121,7 +122,7 @@ parse_geo_point( klv_timeline const& klv_data,
   }
   if( !longitude.valid() )
   {
-    return kv::nullopt;
+    return std::nullopt;
   }
 
   klv_value elevation;
@@ -283,7 +284,7 @@ klv_0104_to_vital_metadata( klv_timeline const& klv_data, uint64_t timestamp,
   }
 
   // Image frame corner point locations
-  std::vector< kv::optional< kv::geo_point > > corner_points = {
+  std::vector< std::optional< kv::geo_point > > corner_points = {
     parse_geo_point( klv_data, standard, timestamp,
                      { KLV_0104_CORNER_LATITUDE_POINT_1 },
                      { KLV_0104_CORNER_LONGITUDE_POINT_1 },
@@ -303,7 +304,7 @@ klv_0104_to_vital_metadata( klv_timeline const& klv_data, uint64_t timestamp,
 
   // Add the frame corners if we found all of them
   if( std::all_of( corner_points.cbegin(), corner_points.cend(),
-                   []( kv::optional< kv::geo_point > const& value ) -> bool {
+                   []( std::optional< kv::geo_point > const& value ) -> bool {
                      return value.has_value();
                    } ) )
   {
@@ -476,7 +477,7 @@ klv_0601_to_vital_metadata( klv_timeline const& klv_data, uint64_t timestamp,
   }
 
   // Image frame corner point locations
-  std::vector< kv::optional< kv::geo_point > > corner_points = {
+  std::vector< std::optional< kv::geo_point > > corner_points = {
     parse_geo_point( klv_data, standard, timestamp,
                      { KLV_0601_FULL_CORNER_LATITUDE_POINT_1 },
                      { KLV_0601_FULL_CORNER_LONGITUDE_POINT_1 },
@@ -499,7 +500,7 @@ klv_0601_to_vital_metadata( klv_timeline const& klv_data, uint64_t timestamp,
   {
     auto const target_location_vector =
       target_location->location( kv::SRID::lat_lon_WGS84 );
-    std::vector< kv::optional< kv::geo_point > > const offset_corner_points = {
+    std::vector< std::optional< kv::geo_point > > const offset_corner_points = {
       parse_geo_point( klv_data, standard, timestamp,
                        { KLV_0601_OFFSET_CORNER_LATITUDE_POINT_1 },
                        { KLV_0601_OFFSET_CORNER_LONGITUDE_POINT_1 },
@@ -533,7 +534,7 @@ klv_0601_to_vital_metadata( klv_timeline const& klv_data, uint64_t timestamp,
 
   // Add the frame corners if we found all of them
   if( std::all_of( corner_points.cbegin(), corner_points.cend(),
-                   []( kv::optional< kv::geo_point > const& value ) -> bool {
+                   []( std::optional< kv::geo_point > const& value ) -> bool {
                      return value.has_value();
                    } ) )
   {
@@ -564,7 +565,7 @@ klv_1108_to_vital_metadata( klv_timeline const& klv_data, uint64_t timestamp,
   // metric
   for( auto const& metric : metrics )
   {
-    kv::optional< klv_local_set > best_metric_set;
+    std::optional< klv_local_set > best_metric_set;
     for( auto const& metric_set_entry :
          klv_data.all_at( standard, KLV_1108_METRIC_LOCAL_SET, timestamp ) )
     {
diff --git a/arrows/klv/klv_demuxer.cxx b/arrows/klv/klv_demuxer.cxx
index 03ed1eb6e4..73f63a2162 100644
--- a/arrows/klv/klv_demuxer.cxx
+++ b/arrows/klv/klv_demuxer.cxx
@@ -76,7 +76,7 @@ ::klv_demuxer( klv_timeline& timeline )
 void
 klv_demuxer
 ::send_frame( std::vector< klv_packet > const& packets,
-              kv::optional< uint64_t > backup_timestamp )
+              std::optional< uint64_t > backup_timestamp )
 {
   m_prev_frame_timestamp = m_frame_timestamp;
 
diff --git a/arrows/klv/klv_demuxer.h b/arrows/klv/klv_demuxer.h
index bc35687a5a..48757028ca 100644
--- a/arrows/klv/klv_demuxer.h
+++ b/arrows/klv/klv_demuxer.h
@@ -7,6 +7,8 @@
 
 #include "klv_timeline.h"
 
+#include <optional>
+
 namespace kwiver {
 
 namespace arrows {
@@ -28,8 +30,8 @@ class KWIVER_ALGO_KLV_EXPORT klv_demuxer
   /// Incorporate \p packets into the timeline.
   void send_frame(
     std::vector< klv_packet > const& packets,
-    kwiver::vital::optional< uint64_t > backup_timestamp =
-      kwiver::vital::nullopt );
+    std::optional< uint64_t > backup_timestamp =
+      std::nullopt );
 
   /// Return the timestamp of the most recent frame.
   uint64_t frame_time() const;
diff --git a/arrows/klv/klv_length_constraints.cxx b/arrows/klv/klv_length_constraints.cxx
index ebbb1175a0..a0ec26db0f 100644
--- a/arrows/klv/klv_length_constraints.cxx
+++ b/arrows/klv/klv_length_constraints.cxx
@@ -140,7 +140,7 @@ ::is_free() const
 }
 
 // ----------------------------------------------------------------------------
-vital::optional< size_t >
+std::optional< size_t >
 klv_length_constraints
 ::fixed() const
 {
@@ -151,7 +151,7 @@ ::fixed() const
   }
   else
   {
-    return vital::nullopt;
+    return std::nullopt;
   }
 }
 
@@ -172,7 +172,7 @@ ::fixed_or( size_t backup ) const
 }
 
 // ----------------------------------------------------------------------------
-vital::optional< vital::interval< size_t > >
+std::optional< vital::interval< size_t > >
 klv_length_constraints
 ::interval() const
 {
@@ -183,12 +183,12 @@ ::interval() const
   }
   else
   {
-    return vital::nullopt;
+    return std::nullopt;
   }
 }
 
 // ----------------------------------------------------------------------------
-vital::optional< std::set< size_t > >
+std::optional< std::set< size_t > >
 klv_length_constraints
 ::set() const
 {
@@ -199,7 +199,7 @@ ::set() const
   }
   else
   {
-    return vital::nullopt;
+    return std::nullopt;
   }
 }
 
diff --git a/arrows/klv/klv_length_constraints.h b/arrows/klv/klv_length_constraints.h
index 1740f6d474..a44ff75f3b 100644
--- a/arrows/klv/klv_length_constraints.h
+++ b/arrows/klv/klv_length_constraints.h
@@ -10,10 +10,10 @@
 
 #include <arrows/klv/kwiver_algo_klv_export.h>
 
-#include <vital/optional.h>
 #include <vital/util/interval.h>
 #include <vital/util/variant/variant.hpp>
 
+#include <optional>
 #include <set>
 
 namespace kwiver {
@@ -51,7 +51,7 @@ class KWIVER_ALGO_KLV_EXPORT klv_length_constraints
   is_free() const;
 
   /// Returns the single value the length is fixed to, if it exists.
-  vital::optional< size_t >
+  std::optional< size_t >
   fixed() const;
 
   /// Returns the fixed length, or \p backup if the length is not fixed.
@@ -59,11 +59,11 @@ class KWIVER_ALGO_KLV_EXPORT klv_length_constraints
   fixed_or( size_t backup ) const;
 
   /// Returns the interval of allowed lengths, if it exists.
-  vital::optional< vital::interval< size_t > >
+  std::optional< vital::interval< size_t > >
   interval() const;
 
   /// Returns the set of allowed lengths, if it exists.
-  vital::optional< std::set< size_t > >
+  std::optional< std::set< size_t > >
   set() const;
 
   /// Return a suggested, valid length.
@@ -82,7 +82,7 @@ class KWIVER_ALGO_KLV_EXPORT klv_length_constraints
   vital::variant<
     vital::monostate, size_t, vital::interval< size_t >, std::set< size_t >
     > m_impl;
-  vital::optional< size_t > m_suggested;
+  std::optional< size_t > m_suggested;
 };
 
 } // namespace klv
diff --git a/arrows/klv/klv_length_value.h b/arrows/klv/klv_length_value.h
index 63c0c84deb..c362c96e24 100644
--- a/arrows/klv/klv_length_value.h
+++ b/arrows/klv/klv_length_value.h
@@ -12,8 +12,7 @@
 #include <arrows/klv/klv_util.h>
 #include <arrows/klv/kwiver_algo_klv_export.h>
 
-#include <vital/optional.h>
-
+#include <optional>
 #include <tuple>
 
 namespace kwiver {
@@ -75,7 +74,7 @@ template < class Format >
 void
 write_trunc_lv_impl(
   std::tuple<
-    kwiver::vital::optional< typename Format::data_type > const&
+    std::optional< typename Format::data_type > const&
     > const& value,
   klv_write_iter_t& data, size_t length,
   Format const& format )
@@ -95,8 +94,8 @@ template < class Format, class... Formats,
                                     bool >::type = true >
 void
 write_trunc_lv_impl(
-  std::tuple< kwiver::vital::optional< typename Format::data_type > const&,
-              kwiver::vital::optional< typename Formats::data_type > const&...
+  std::tuple< std::optional< typename Format::data_type > const&,
+              std::optional< typename Formats::data_type > const&...
               > const& value,
   klv_write_iter_t& data, size_t length,
   Format format, Formats const&... formats )
@@ -133,7 +132,7 @@ klv_read_lv(
 // If the length is 0, returns `nullopt`. `max_length` should be
 /// greater than 0.
 template < class Format >
-kwiver::vital::optional< typename Format::data_type >
+std::optional< typename Format::data_type >
 klv_read_opt_lv(
   klv_read_iter_t& data, size_t max_length,
   Format const& format )
@@ -142,7 +141,7 @@ klv_read_opt_lv(
   auto const length = klv_read_ber< size_t >( data, tracker.remaining() );
   if( !length )
   {
-    return kwiver::vital::nullopt;
+    return std::nullopt;
   }
 
   auto const value = format.read_( data, tracker.verify( length ) );
@@ -153,14 +152,14 @@ klv_read_opt_lv(
 // Read in a value, defined by `format`, preceded by its BER-encoded length.
 // If `max_length` or the actual length is 0, returns `nullopt`.
 template < class Format >
-kwiver::vital::optional< typename Format::data_type >
+std::optional< typename Format::data_type >
 klv_read_trunc_lv(
   klv_read_iter_t& data, size_t max_length,
   Format const& format )
 {
   return max_length
          ? klv_read_opt_lv( data, max_length, format )
-         : kwiver::vital::nullopt;
+         : std::nullopt;
 }
 
 // ----------------------------------------------------------------------------
@@ -186,7 +185,7 @@ klv_write_lv(
 template < class Format >
 void
 klv_write_opt_lv(
-  kwiver::vital::optional< typename Format::data_type > const& value,
+  std::optional< typename Format::data_type > const& value,
   klv_write_iter_t& data, size_t max_length,
   Format const& format )
 {
@@ -205,7 +204,7 @@ template < class Format >
 void
 klv_write_trunc_lv(
   std::tuple<
-    kwiver::vital::optional< typename Format::data_type const& >
+    std::optional< typename Format::data_type const& >
     > const& value,
   klv_write_iter_t& data, size_t length,
   Format const& format )
@@ -224,8 +223,8 @@ template < class Format, class... Formats,
 void
 klv_write_trunc_lv(
   std::tuple<
-    kwiver::vital::optional< typename Format::data_type > const&,
-    kwiver::vital::optional< typename Formats::data_type > const&...
+    std::optional< typename Format::data_type > const&,
+    std::optional< typename Formats::data_type > const&...
     > const& value,
   klv_write_iter_t& data, size_t max_length,
   Format const& format, Formats const&... formats )
@@ -256,7 +255,7 @@ klv_length_of_lv( typename Format::data_type const& value,
 template < class Format >
 size_t
 klv_length_of_opt_lv(
-  kwiver::vital::optional< typename Format::data_type > const& value,
+  std::optional< typename Format::data_type > const& value,
   Format const& format )
 {
   auto const length = value ? format.length_of_( *value ) : 0;
@@ -268,7 +267,7 @@ klv_length_of_opt_lv(
 template < class Format >
 size_t
 klv_length_of_trunc_lv(
-  std::tuple< kwiver::vital::optional< typename Format::data_type > const&
+  std::tuple< std::optional< typename Format::data_type > const&
               > const& value,
   Format const& format )
 {
@@ -285,8 +284,8 @@ template < class Format, class... Formats,
                                     bool >::type = true >
 size_t
 klv_length_of_trunc_lv(
-  std::tuple< kwiver::vital::optional< typename Format::data_type > const&,
-              kwiver::vital::optional< typename Formats::data_type > const&...
+  std::tuple< std::optional< typename Format::data_type > const&,
+              std::optional< typename Formats::data_type > const&...
               > const& value,
   Format const& format, Formats const&... formats )
 {
diff --git a/arrows/klv/klv_lengthy.cxx b/arrows/klv/klv_lengthy.cxx
index f90ad50239..cc8cc008bd 100644
--- a/arrows/klv/klv_lengthy.cxx
+++ b/arrows/klv/klv_lengthy.cxx
@@ -9,7 +9,7 @@
 
 #include <arrows/klv/klv_util.h>
 
-#include <vital/optional.h>
+#include <optional>
 
 namespace kwiver {
 
@@ -117,7 +117,7 @@ operator!=( klv_lengthy< T > const& lhs, klv_lengthy< T > const& rhs )
   template bool operator!=( klv_lengthy< T > const&, klv_lengthy< T > const& )
 
 KLV_INSTANTIATE( double );
-KLV_INSTANTIATE( kwiver::vital::optional< double > );
+KLV_INSTANTIATE( std::optional< double > );
 
 } // namespace klv
 
diff --git a/arrows/klv/klv_packet.cxx b/arrows/klv/klv_packet.cxx
index 293a73a4ae..2819694092 100644
--- a/arrows/klv/klv_packet.cxx
+++ b/arrows/klv/klv_packet.cxx
@@ -211,25 +211,25 @@ klv_packet_length( klv_packet const& packet )
 }
 
 // ----------------------------------------------------------------------------
-kv::optional< uint64_t >
+std::optional< uint64_t >
 klv_packet_timestamp( klv_packet const& packet )
 {
   if( !packet.value.valid() )
   {
-    return kv::nullopt;
+    return std::nullopt;
   }
 
-  auto const get_local = [&]( klv_lds_key key ) -> kv::optional< uint64_t > {
+  auto const get_local = [&]( klv_lds_key key ) -> std::optional< uint64_t > {
     auto const& set = packet.value.get< klv_local_set >();
     auto const it = set.find( KLV_0601_PRECISION_TIMESTAMP );
     if ( it != set.end() && it->second.valid() )
     {
       return it->second.get< uint64_t >();
     }
-    return kv::nullopt;
+    return std::nullopt;
   };
 
-  kv::optional< uint64_t > result;
+  std::optional< uint64_t > result;
   switch( klv_lookup_packet_traits().by_uds_key( packet.key ).tag() )
   {
     case KLV_PACKET_MISB_0104_UNIVERSAL_SET:
diff --git a/arrows/klv/klv_packet.h b/arrows/klv/klv_packet.h
index dd7bea7f3e..b65ccd82f4 100644
--- a/arrows/klv/klv_packet.h
+++ b/arrows/klv/klv_packet.h
@@ -16,6 +16,8 @@
 
 #include <vital/types/timestamp.h>
 
+#include <optional>
+
 namespace kwiver {
 
 namespace arrows {
@@ -135,7 +137,7 @@ klv_packet_length( klv_packet const& packet );
 ///
 /// \returns Packet timestamp in microseconds, or \c nullopt on failure.
 KWIVER_ALGO_KLV_EXPORT
-kwiver::vital::optional< uint64_t >
+std::optional< uint64_t >
 klv_packet_timestamp( klv_packet const& packet );
 
 // ----------------------------------------------------------------------------
diff --git a/arrows/klv/klv_update_intervals.cxx b/arrows/klv/klv_update_intervals.cxx
index b21190b089..e8c8aced69 100644
--- a/arrows/klv/klv_update_intervals.cxx
+++ b/arrows/klv/klv_update_intervals.cxx
@@ -27,7 +27,7 @@ ::key_t( klv_top_level_tag standard ) : standard{ standard }, tag{}
 // ----------------------------------------------------------------------------
 klv_update_intervals::key_t
 ::key_t(
-  klv_top_level_tag standard, kwiver::vital::optional< klv_lds_key > tag )
+  klv_top_level_tag standard, std::optional< klv_lds_key > tag )
   : standard{ standard }, tag{ tag }
 {}
 
@@ -51,7 +51,7 @@ ::at( key_t const& key ) const
   auto const it = m_map.find( key );
   if( it == m_map.end() )
   {
-    auto const jt = m_map.find( { key.standard, kv::nullopt } );
+    auto const jt = m_map.find( { key.standard, std::nullopt } );
     return ( jt == m_map.end() ) ? m_default : jt->second;
   }
   return it->second;
diff --git a/arrows/klv/klv_update_intervals.h b/arrows/klv/klv_update_intervals.h
index 31571cf82a..ce11448eaf 100644
--- a/arrows/klv/klv_update_intervals.h
+++ b/arrows/klv/klv_update_intervals.h
@@ -12,6 +12,8 @@
 
 #include <vital/util/variant/variant.hpp>
 
+#include <optional>
+
 namespace kwiver {
 
 namespace arrows {
@@ -49,10 +51,10 @@ class KWIVER_ALGO_KLV_EXPORT klv_update_intervals
   struct KWIVER_ALGO_KLV_EXPORT key_t
   {
     key_t( klv_top_level_tag standard );
-    key_t( klv_top_level_tag standard, vital::optional< klv_lds_key > tag );
+    key_t( klv_top_level_tag standard, std::optional< klv_lds_key > tag );
 
     klv_top_level_tag standard;
-    vital::optional< klv_lds_key > tag;
+    std::optional< klv_lds_key > tag;
   };
 
   using value_t = uint64_t;
diff --git a/arrows/klv/klv_util.h b/arrows/klv/klv_util.h
index afe4580ed4..32d6753593 100644
--- a/arrows/klv/klv_util.h
+++ b/arrows/klv/klv_util.h
@@ -9,9 +9,9 @@
 #define KWIVER_ARROWS_KLV_KLV_UTIL_H_
 
 #include <vital/exceptions.h>
-#include <vital/optional.h>
 #include <vital/util/interval.h>
 
+#include <optional>
 #include <ostream>
 #include <set>
 #include <tuple>
@@ -38,7 +38,7 @@ operator<<( std::ostream& os, vital::interval< T > const& value )
 // ----------------------------------------------------------------------------
 template < class T >
 std::ostream&
-operator<<( std::ostream& os, kwiver::vital::optional< T > const& value )
+operator<<( std::ostream& os, std::optional< T > const& value )
 {
   if( value )
   {
diff --git a/arrows/klv/update_klv.cxx b/arrows/klv/update_klv.cxx
index c7e76c2ea7..823e5b9fe8 100644
--- a/arrows/klv/update_klv.cxx
+++ b/arrows/klv/update_klv.cxx
@@ -15,6 +15,8 @@
 #include <arrows/klv/klv_1108_metric_set.h>
 #include <arrows/klv/misp_time.h>
 
+#include <optional>
+
 namespace kwiver {
 
 namespace arrows {
@@ -235,7 +237,7 @@ ::filter(
     // Determine the timestamp for this frame
     auto const timestamp_entry =
       klv_md->find( vital::VITAL_META_UNIX_TIMESTAMP );
-    vital::optional< uint64_t > backup_timestamp;
+    std::optional< uint64_t > backup_timestamp;
     if( timestamp_entry )
     {
       backup_timestamp = timestamp_entry.as_uint64();
diff --git a/arrows/serialize/json/klv/load_save_klv.cxx b/arrows/serialize/json/klv/load_save_klv.cxx
index b98804b8a2..c98d00cd96 100644
--- a/arrows/serialize/json/klv/load_save_klv.cxx
+++ b/arrows/serialize/json/klv/load_save_klv.cxx
@@ -14,6 +14,7 @@
 #include <vital/range/iota.h>
 #include <vital/util/visit.h>
 
+#include <optional>
 #include <stdexcept>
 
 using namespace kwiver::arrows::klv;
@@ -554,7 +555,7 @@ class klv_json_saver : public klv_json_base< save_archive >
   }
 
   template< class T >
-  void save( kv::optional< T > const& value )
+  void save( std::optional< T > const& value )
   {
     if( value )
     {
@@ -1023,12 +1024,12 @@ struct klv_json_loader : public klv_json_base< load_archive >
     return result;
   }
 
-  LOAD_CONTAINER_TEMPLATE( kv::optional )
+  LOAD_CONTAINER_TEMPLATE( std::optional )
   T load()
   {
     if( load_null() )
     {
-      return kv::nullopt;
+      return std::nullopt;
     }
 
     return load< typename T::value_type >();
@@ -1055,8 +1056,8 @@ struct klv_json_loader : public klv_json_base< load_archive >
   LOAD_TEMPLATE( klv_timed_packet )
   T load()
   {
-    LOAD_VALUE( frame, kv::optional< int64_t > );
-    LOAD_VALUE( microseconds, kv::optional< int64_t > );
+    LOAD_VALUE( frame, std::optional< int64_t > );
+    LOAD_VALUE( microseconds, std::optional< int64_t > );
     LOAD_VALUE( packet, klv_packet );
     LOAD_VALUE( stream_index, uint64_t );
     kv::timestamp ts;
diff --git a/sprokit/processes/process_explorer_plugin.cxx b/sprokit/processes/process_explorer_plugin.cxx
index 0022af76c1..b74e285ffe 100644
--- a/sprokit/processes/process_explorer_plugin.cxx
+++ b/sprokit/processes/process_explorer_plugin.cxx
@@ -6,6 +6,7 @@
 
 #include <vital/tools/explorer_plugin.h>
 #include <vital/util/wrap_text_block.h>
+#include <vital/exceptions.h>
 #include <vital/util/string.h>
 
 #include <sprokit/pipeline/process.h>
@@ -14,6 +15,7 @@
 #include <sstream>
 #include <iterator>
 #include <fstream>
+#include <optional>
 #include <string>
 #include <regex>
 
@@ -136,7 +138,7 @@ explore( const kwiver::vital::plugin_factory_handle_t fact )
   {
     proc = pf->create_object( kwiver::vital::config_block::empty_config() );
   }
-  catch ( ::kwiver::vital::exception const& e )
+  catch ( kwiver::vital::vital_exception const& e )
   {
     LOG_ERROR( m_logger, "Exception caught creating process: " << e.what() );
     return;
diff --git a/sprokit/src/sprokit/pipeline/edge.cxx b/sprokit/src/sprokit/pipeline/edge.cxx
index f5fa04c00a..a10a65d53d 100644
--- a/sprokit/src/sprokit/pipeline/edge.cxx
+++ b/sprokit/src/sprokit/pipeline/edge.cxx
@@ -85,8 +85,8 @@ class edge::priv
     bool full_of_data() const;
     void complete_check() const;
 
-    bool push(edge_datum_t const& datum, kwiver::vital::optional<duration_t> const& duration = kwiver::vital::nullopt);
-    kwiver::vital::optional<edge_datum_t> pop(kwiver::vital::optional<duration_t> const& duration = kwiver::vital::nullopt);
+    bool push(edge_datum_t const& datum, std::optional<duration_t> const& duration = std::nullopt);
+    std::optional<edge_datum_t> pop(std::optional<duration_t> const& duration = std::nullopt);
 
     /// This flag indicates that this edge connection should or should
     /// not imply a dependency. Generally set to false if a backwards
@@ -271,7 +271,7 @@ ::try_push_datum(edge_datum_t const& datum, duration_t const& duration)
 }
 
 // ------------------------------------------------------------------
-kwiver::vital::optional<edge_datum_t>
+std::optional<edge_datum_t>
 edge
 ::try_get_datum(duration_t const& duration)
 {
@@ -408,7 +408,7 @@ ::complete_check() const
 // ------------------------------------------------------------------
 bool
 edge::priv
-::push(edge_datum_t const& datum, kwiver::vital::optional<duration_t> const& duration)
+::push(edge_datum_t const& datum, std::optional<duration_t> const& duration)
 {
   {
     shared_lock_t const lock(complete_mutex);
@@ -454,9 +454,9 @@ ::push(edge_datum_t const& datum, kwiver::vital::optional<duration_t> const& dur
 }
 
 // ------------------------------------------------------------------
-kwiver::vital::optional<edge_datum_t>
+std::optional<edge_datum_t>
 edge::priv
-::pop(kwiver::vital::optional<duration_t> const& duration)
+::pop(std::optional<duration_t> const& duration)
 {
   complete_check();
 
@@ -470,7 +470,7 @@ ::pop(kwiver::vital::optional<duration_t> const& duration)
     {
       if (!cond_have_data.wait_for(lock, *duration, predicate))
       {
-        return kwiver::vital::nullopt;
+        return std::nullopt;
       }
     }
     else
diff --git a/sprokit/src/sprokit/pipeline/edge.h b/sprokit/src/sprokit/pipeline/edge.h
index 8a2748927a..3c85f113a8 100644
--- a/sprokit/src/sprokit/pipeline/edge.h
+++ b/sprokit/src/sprokit/pipeline/edge.h
@@ -9,7 +9,6 @@
 
 #include <vital/config/config_block.h>
 #include <vital/noncopyable.h>
-#include <vital/optional.h>
 
 #include "types.h"
 
@@ -24,6 +23,7 @@
 #pragma warning (pop)
 #endif
 
+#include <optional>
 #include <vector>
 
 /**
@@ -249,7 +249,7 @@ class SPROKIT_PIPELINE_EXPORT edge
    *
    * \returns The next datum available from the edge, or \c boost::none if the timeout was reached.
    */
-  kwiver::vital::optional< edge_datum_t > try_get_datum( duration_t const& duration );
+  std::optional< edge_datum_t > try_get_datum( duration_t const& duration );
 
   /**
    * \brief Trigger the edge to flush all data and not accept any more data.
diff --git a/sprokit/src/sprokit/pipeline/process.cxx b/sprokit/src/sprokit/pipeline/process.cxx
index b98a83d739..c5970e9196 100644
--- a/sprokit/src/sprokit/pipeline/process.cxx
+++ b/sprokit/src/sprokit/pipeline/process.cxx
@@ -10,7 +10,6 @@
 
 #include <vital/plugin_loader/plugin_manager.h>
 #include <vital/util/string.h>
-#include <vital/optional.h>
 #include <vital/vital_config.h>
 
 #include <boost/assign/ptr_map_inserter.hpp>
@@ -166,14 +165,14 @@ class process::priv
 
     typedef port_t tag_t;
 
-    typedef kwiver::vital::optional<port_type_t> flow_tag_port_type_t;
+    typedef std::optional<port_type_t> flow_tag_port_type_t;
     typedef std::map<tag_t, flow_tag_port_type_t> flow_tag_port_type_map_t;
 
     typedef std::map<tag_t, ports_t> flow_tag_port_map_t;
 
     typedef std::map<port_t, tag_t> port_tag_map_t;
 
-    typedef kwiver::vital::optional<port_frequency_t> core_frequency_t;
+    typedef std::optional<port_frequency_t> core_frequency_t;
 
     tag_t port_flow_tag_name(port_type_t const& port_type) const;
     void check_tag(tag_t const& tag);
diff --git a/sprokit/src/sprokit/pipeline_util/cluster_bakery.h b/sprokit/src/sprokit/pipeline_util/cluster_bakery.h
index 2943ae49d5..026425736d 100644
--- a/sprokit/src/sprokit/pipeline_util/cluster_bakery.h
+++ b/sprokit/src/sprokit/pipeline_util/cluster_bakery.h
@@ -12,8 +12,7 @@
 
 #include "bakery_base.h"
 
-#include <vital/optional.h>
-
+#include <optional>
 #include <vector>
 
 namespace sprokit {
@@ -51,7 +50,7 @@ class cluster_bakery
     input_maps_t m_inputs;
     output_maps_t m_outputs;
   };
-  typedef kwiver::vital::optional< cluster_component_info_t > opt_cluster_component_info_t;
+  typedef std::optional< cluster_component_info_t > opt_cluster_component_info_t;
 
   /// Name of the cluster.
   process::type_t m_type;
diff --git a/vital/CMakeLists.txt b/vital/CMakeLists.txt
index 1d78e6c656..3bb7e44a5a 100644
--- a/vital/CMakeLists.txt
+++ b/vital/CMakeLists.txt
@@ -79,7 +79,6 @@ set( vital_public_headers
   iterator.h
   math_constants.h
   noncopyable.h
-  optional.h
   set.h
   signal.h
 
diff --git a/vital/optional.h b/vital/optional.h
deleted file mode 100644
index 069d69ce71..0000000000
--- a/vital/optional.h
+++ /dev/null
@@ -1,1030 +0,0 @@
-// Copyright (C) 2011 - 2012 Andrzej Krzemienski.
-//
-// Use, modification, and distribution is subject to the Boost Software
-// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-// The idea and interface is based on Boost.Optional library
-// authored by Fernando Luis Cacciola Carballal
-//
-// Added to Kwiver as a place-holder until optional is added to std.
-
-# ifndef _VITAL_INTERNAL_OPTIONAL_HPP___
-# define _VITAL_INTERNAL_OPTIONAL_HPP___
-
-# include <utility>
-# include <type_traits>
-# include <initializer_list>
-# include <cassert>
-# include <functional>
-# include <string>
-# include <stdexcept>
-
-# define TR2_OPTIONAL_REQUIRES(...) typename std::enable_if<__VA_ARGS__::value, bool>::type = false
-
-# if defined __GNUC__ // NOTE: GNUC is also defined for Clang
-#   if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)
-#     define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___
-#   elif (__GNUC__ > 4)
-#     define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___
-#   endif
-#
-#   if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)
-#     define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___
-#   elif (__GNUC__ > 4)
-#     define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___
-#   endif
-#
-#   if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ >= 1)
-#     define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
-#   elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)
-#     define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
-#   elif (__GNUC__ > 4)
-#     define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
-#   endif
-# endif
-#
-# if defined __clang_major__
-#   if (__clang_major__ == 3 && __clang_minor__ >= 5)
-#     define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_
-#   elif (__clang_major__ > 3)
-#     define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_
-#   endif
-#   if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_
-#     define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
-#   elif (__clang_major__ == 3 && __clang_minor__ == 4 && __clang_patchlevel__ >= 2)
-#     define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
-#   endif
-# endif
-#
-# if defined _MSC_VER
-#   if (_MSC_VER >= 1900)
-#     define TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
-#   endif
-# endif
-
-# if defined __clang__
-#   if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9)
-#     define OPTIONAL_HAS_THIS_RVALUE_REFS 1
-#   else
-#     define OPTIONAL_HAS_THIS_RVALUE_REFS 0
-#   endif
-# elif defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
-#   define OPTIONAL_HAS_THIS_RVALUE_REFS 1
-# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
-#   define OPTIONAL_HAS_THIS_RVALUE_REFS 1
-# else
-#   define OPTIONAL_HAS_THIS_RVALUE_REFS 0
-# endif
-
-
-# if defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___
-#   define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 1
-#   define OPTIONAL_CONSTEXPR_INIT_LIST constexpr
-# else
-#   define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 0
-#   define OPTIONAL_CONSTEXPR_INIT_LIST
-# endif
-
-# if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ && (defined __cplusplus) && (__cplusplus != 201103L)
-#   define OPTIONAL_HAS_MOVE_ACCESSORS 1
-# else
-#   define OPTIONAL_HAS_MOVE_ACCESSORS 0
-# endif
-
-# // In C++11 constexpr implies const, so we need to make non-const members also non-constexpr
-# if (defined __cplusplus) && (__cplusplus == 201103L)
-#   define OPTIONAL_MUTABLE_CONSTEXPR
-# else
-#   define OPTIONAL_MUTABLE_CONSTEXPR constexpr
-# endif
-
-namespace kwiver {
-namespace vital {
-
-using namespace std;
-
-// BEGIN workaround for missing is_trivially_destructible
-# if defined TR2_OPTIONAL_GCC_4_8_AND_HIGHER___
-    // leave it: it is already there
-# elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
-    // leave it: it is already there
-# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
-    // leave it: it is already there
-# elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS
-    // leave it: the user doesn't want it
-# else
-	template <typename T>
-	using is_trivially_destructible = std::has_trivial_destructor<T>;
-# endif
-// END workaround for missing is_trivially_destructible
-
-# if (defined TR2_OPTIONAL_GCC_4_7_AND_HIGHER___)
-    // leave it; our metafunctions are already defined.
-# elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_
-    // leave it; our metafunctions are already defined.
-# elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___
-    // leave it: it is already there
-# elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS
-    // leave it: the user doesn't want it
-# else
-
-
-// workaround for missing traits in GCC and CLANG
-template <class T>
-struct is_nothrow_move_constructible
-{
-  constexpr static bool value = std::is_nothrow_constructible<T, T&&>::value;
-};
-
-
-template <class T, class U>
-struct is_assignable
-{
-  template <class X, class Y>
-  constexpr static bool has_assign(...) { return false; }
-
-  template <class X, class Y, size_t S = sizeof((std::declval<X>() = std::declval<Y>(), true)) >
-  // the comma operator is necessary for the cases where operator= returns void
-  constexpr static bool has_assign(bool) { return true; }
-
-  constexpr static bool value = has_assign<T, U>(true);
-};
-
-
-template <class T>
-struct is_nothrow_move_assignable
-{
-  template <class X, bool has_any_move_assign>
-  struct has_nothrow_move_assign {
-    constexpr static bool value = false;
-  };
-
-  template <class X>
-  struct has_nothrow_move_assign<X, true> {
-    constexpr static bool value = noexcept( std::declval<X&>() = std::declval<X&&>() );
-  };
-
-  constexpr static bool value = has_nothrow_move_assign<T, is_assignable<T&, T&&>::value>::value;
-};
-// end workaround
-
-
-# endif
-
-
-
-// 20.5.4, optional for object types
-template <class T> class optional;
-
-// 20.5.5, optional for lvalue reference types
-template <class T> class optional<T&>;
-
-
-// workaround: std utility functions aren't constexpr yet
-template <class T> inline constexpr T&& constexpr_forward(typename std::remove_reference<T>::type& t) noexcept
-{
-  return static_cast<T&&>(t);
-}
-
-template <class T> inline constexpr T&& constexpr_forward(typename std::remove_reference<T>::type&& t) noexcept
-{
-    static_assert(!std::is_lvalue_reference<T>::value, "!!");
-    return static_cast<T&&>(t);
-}
-
-template <class T> inline constexpr typename std::remove_reference<T>::type&& constexpr_move(T&& t) noexcept
-{
-    return static_cast<typename std::remove_reference<T>::type&&>(t);
-}
-
-
-#if defined NDEBUG
-# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR)
-#else
-# define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) ((CHECK) ? (EXPR) : ([]{assert(!#CHECK);}(), (EXPR)))
-#endif
-
-
-namespace detail_ {
-
-// static_addressof: a constexpr version of addressof
-template <typename T>
-struct has_overloaded_addressof
-{
-  template <class X>
-  constexpr static bool has_overload(...) { return false; }
-
-  template <class X, size_t S = sizeof(std::declval<X&>().operator&()) >
-  constexpr static bool has_overload(bool) { return true; }
-
-  constexpr static bool value = has_overload<T>(true);
-};
-
-template <typename T, TR2_OPTIONAL_REQUIRES(!has_overloaded_addressof<T>)>
-constexpr T* static_addressof(T& ref)
-{
-  return &ref;
-}
-
-template <typename T, TR2_OPTIONAL_REQUIRES(has_overloaded_addressof<T>)>
-T* static_addressof(T& ref)
-{
-  return std::addressof(ref);
-}
-
-// the call to convert<A>(b) has return type A and converts b to type
-// A iff b decltype(b) is implicitly convertible to A
-template <class U>
-constexpr U convert(U v) { return v; }
-
-
-namespace swap_ns
-{
-  using std::swap;
-
-  template <class T>
-  void adl_swap(T& t, T& u) noexcept(noexcept(swap(t, u)))
-  {
-    swap(t, u);
-  }
-
-} // namespace swap_ns
-
-} // namespace detail
-
-
-constexpr struct trivial_init_t{} trivial_init{};
-
-
-// 20.5.7, Disengaged state indicator
-struct nullopt_t
-{
-  struct init{};
-  constexpr explicit nullopt_t(init){}
-};
-constexpr nullopt_t nullopt{nullopt_t::init()};
-
-
-// 20.5.8, class bad_optional_access
-class bad_optional_access : public std::logic_error {
-public:
-  explicit bad_optional_access(const string& what_arg) : logic_error{what_arg} {}
-  explicit bad_optional_access(const char* what_arg) : logic_error{what_arg} {}
-};
-
-
-template <class T>
-union storage_t
-{
-  unsigned char dummy_;
-  T value_;
-
-  constexpr storage_t( trivial_init_t ) noexcept : dummy_() {};
-
-  template <class... Args>
-  constexpr storage_t( Args&&... args ) : value_(constexpr_forward<Args>(args)...) {}
-
-  ~storage_t(){}
-};
-
-
-template <class T>
-union constexpr_storage_t
-{
-    unsigned char dummy_;
-    T value_;
-
-    constexpr constexpr_storage_t( trivial_init_t ) noexcept : dummy_() {};
-
-    template <class... Args>
-    constexpr constexpr_storage_t( Args&&... args ) : value_(constexpr_forward<Args>(args)...) {}
-
-    ~constexpr_storage_t() = default;
-};
-
-
-template <class T>
-struct optional_base
-{
-    bool init_;
-    storage_t<T> storage_;
-
-    constexpr optional_base() noexcept : init_(false), storage_(trivial_init) {};
-
-    explicit constexpr optional_base(const T& v) : init_(true), storage_(v) {}
-
-    explicit constexpr optional_base(T&& v) : init_(true), storage_(constexpr_move(v)) {}
-
-    ~optional_base() { if (init_) storage_.value_.T::~T(); }
-};
-
-
-template <class T>
-struct constexpr_optional_base
-{
-    bool init_;
-    constexpr_storage_t<T> storage_;
-
-    constexpr constexpr_optional_base() noexcept : init_(false), storage_(trivial_init) {};
-
-    explicit constexpr constexpr_optional_base(const T& v) : init_(true), storage_(v) {}
-
-    explicit constexpr constexpr_optional_base(T&& v) : init_(true), storage_(constexpr_move(v)) {}
-
-    ~constexpr_optional_base() = default;
-};
-
-template <class T>
-using OptionalBase = typename std::conditional<
-    is_trivially_destructible<T>::value,                          // if possible
-    constexpr_optional_base<typename std::remove_const<T>::type>, // use base with trivial destructor
-    optional_base<typename std::remove_const<T>::type>
->::type;
-
-
-
-template <class T>
-class optional : private OptionalBase<T>
-{
-  static_assert( !std::is_same<typename std::decay<T>::type, nullopt_t>::value, "bad T" );
-
-  constexpr bool initialized() const noexcept { return OptionalBase<T>::init_; }
-  typename std::remove_const<T>::type* dataptr() {  return std::addressof(OptionalBase<T>::storage_.value_); }
-  constexpr const T* dataptr() const { return detail_::static_addressof(OptionalBase<T>::storage_.value_); }
-
-# if OPTIONAL_HAS_THIS_RVALUE_REFS == 1
-  constexpr const T& contained_val() const& { return OptionalBase<T>::storage_.value_; }
-#   if OPTIONAL_HAS_MOVE_ACCESSORS == 1
-  OPTIONAL_MUTABLE_CONSTEXPR T&& contained_val() && { return std::move(OptionalBase<T>::storage_.value_); }
-  OPTIONAL_MUTABLE_CONSTEXPR T& contained_val() & { return OptionalBase<T>::storage_.value_; }
-#   else
-  T& contained_val() & { return OptionalBase<T>::storage_.value_; }
-  T&& contained_val() && { return std::move(OptionalBase<T>::storage_.value_); }
-#   endif
-# else
-  constexpr const T& contained_val() const { return OptionalBase<T>::storage_.value_; }
-  T& contained_val() { return OptionalBase<T>::storage_.value_; }
-# endif
-
-  void clear() noexcept {
-    if (initialized()) dataptr()->T::~T();
-    OptionalBase<T>::init_ = false;
-  }
-
-  template <class... Args>
-  void initialize(Args&&... args) noexcept(noexcept(T(std::forward<Args>(args)...)))
-  {
-    assert(!OptionalBase<T>::init_);
-    ::new (static_cast<void*>(dataptr())) T(std::forward<Args>(args)...);
-    OptionalBase<T>::init_ = true;
-  }
-
-  template <class U, class... Args>
-  void initialize(std::initializer_list<U> il, Args&&... args) noexcept(noexcept(T(il, std::forward<Args>(args)...)))
-  {
-    assert(!OptionalBase<T>::init_);
-    ::new (static_cast<void*>(dataptr())) T(il, std::forward<Args>(args)...);
-    OptionalBase<T>::init_ = true;
-  }
-
-public:
-  typedef T value_type;
-
-  // 20.5.5.1, constructors
-  constexpr optional() noexcept : OptionalBase<T>()  {};
-  constexpr optional(nullopt_t) noexcept : OptionalBase<T>() {};
-
-  optional(const optional& rhs)
-  : OptionalBase<T>()
-  {
-    if (rhs.initialized()) {
-        ::new (static_cast<void*>(dataptr())) T(*rhs);
-        OptionalBase<T>::init_ = true;
-    }
-  }
-
-  optional(optional&& rhs) noexcept(is_nothrow_move_constructible<T>::value)
-  : OptionalBase<T>()
-  {
-    if (rhs.initialized()) {
-        ::new (static_cast<void*>(dataptr())) T(std::move(*rhs));
-        OptionalBase<T>::init_ = true;
-    }
-  }
-
-  constexpr optional(const T& v) : OptionalBase<T>(v) {}
-
-  constexpr optional(T&& v) : OptionalBase<T>(constexpr_move(v)) {}
-
-  // 20.5.4.2, Destructor
-  ~optional() = default;
-
-  // 20.5.4.3, assignment
-  optional& operator=(nullopt_t) noexcept
-  {
-    clear();
-    return *this;
-  }
-
-  optional& operator=(const optional& rhs)
-  {
-    if      (initialized() == true  && rhs.initialized() == false) clear();
-    else if (initialized() == false && rhs.initialized() == true)  initialize(*rhs);
-    else if (initialized() == true  && rhs.initialized() == true)  contained_val() = *rhs;
-    return *this;
-  }
-
-  optional& operator=(optional&& rhs)
-  noexcept(is_nothrow_move_assignable<T>::value && is_nothrow_move_constructible<T>::value)
-  {
-    if      (initialized() == true  && rhs.initialized() == false) clear();
-    else if (initialized() == false && rhs.initialized() == true)  initialize(std::move(*rhs));
-    else if (initialized() == true  && rhs.initialized() == true)  contained_val() = std::move(*rhs);
-    return *this;
-  }
-
-  template <class U>
-  auto operator=(U&& v)
-  -> typename enable_if
-  <
-    is_same<typename decay<U>::type, T>::value,
-    optional&
-  >::type
-  {
-    if (initialized()) { contained_val() = std::forward<U>(v); }
-    else               { initialize(std::forward<U>(v));  }
-    return *this;
-  }
-
-
-  template <class... Args>
-  void emplace(Args&&... args)
-  {
-    clear();
-    initialize(std::forward<Args>(args)...);
-  }
-
-  template <class U, class... Args>
-  void emplace(initializer_list<U> il, Args&&... args)
-  {
-    clear();
-    initialize<U, Args...>(il, std::forward<Args>(args)...);
-  }
-
-  // 20.5.4.4, Swap
-  void swap(optional<T>& rhs) noexcept(is_nothrow_move_constructible<T>::value
-                                       && noexcept(detail_::swap_ns::adl_swap(declval<T&>(), declval<T&>())))
-  {
-    if      (initialized() == true  && rhs.initialized() == false) { rhs.initialize(std::move(**this)); clear(); }
-    else if (initialized() == false && rhs.initialized() == true)  { initialize(std::move(*rhs)); rhs.clear(); }
-    else if (initialized() == true  && rhs.initialized() == true)  { using std::swap; swap(**this, *rhs); }
-  }
-
-  // 20.5.4.5, Observers
-
-  explicit constexpr operator bool() const noexcept { return initialized(); }
-  constexpr bool has_value() const noexcept { return initialized(); }
-
-  constexpr T const* operator ->() const {
-    return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), dataptr());
-  }
-
-# if OPTIONAL_HAS_MOVE_ACCESSORS == 1
-
-  OPTIONAL_MUTABLE_CONSTEXPR T* operator ->() {
-    assert (initialized());
-    return dataptr();
-  }
-
-  constexpr T const& operator *() const& {
-    return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val());
-  }
-
-  OPTIONAL_MUTABLE_CONSTEXPR T& operator *() & {
-    assert (initialized());
-    return contained_val();
-  }
-
-  OPTIONAL_MUTABLE_CONSTEXPR T&& operator *() && {
-    assert (initialized());
-    return constexpr_move(contained_val());
-  }
-
-  constexpr T const& value() const& {
-    return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val());
-  }
-
-  OPTIONAL_MUTABLE_CONSTEXPR T& value() & {
-    return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val());
-  }
-
-  OPTIONAL_MUTABLE_CONSTEXPR T&& value() && {
-    if (!initialized()) throw bad_optional_access("bad optional access");
-	return std::move(contained_val());
-  }
-
-# else
-
-  T* operator ->() {
-    assert (initialized());
-    return dataptr();
-  }
-
-  constexpr T const& operator *() const {
-    return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val());
-  }
-
-  T& operator *() {
-    assert (initialized());
-    return contained_val();
-  }
-
-  constexpr T const& value() const {
-    return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val());
-  }
-
-  T& value() {
-    return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val());
-  }
-
-# endif
-
-# if OPTIONAL_HAS_THIS_RVALUE_REFS == 1
-
-  template <class V>
-  constexpr T value_or(V&& v) const&
-  {
-    return *this ? **this : detail_::convert<T>(constexpr_forward<V>(v));
-  }
-
-#   if OPTIONAL_HAS_MOVE_ACCESSORS == 1
-
-  template <class V>
-  OPTIONAL_MUTABLE_CONSTEXPR T value_or(V&& v) &&
-  {
-    return *this ? constexpr_move(const_cast<optional<T>&>(*this).contained_val()) : detail_::convert<T>(constexpr_forward<V>(v));
-  }
-
-#   else
-
-  template <class V>
-  T value_or(V&& v) &&
-  {
-    return *this ? constexpr_move(const_cast<optional<T>&>(*this).contained_val()) : detail_::convert<T>(constexpr_forward<V>(v));
-  }
-
-#   endif
-
-# else
-
-  template <class V>
-  constexpr T value_or(V&& v) const
-  {
-    return *this ? **this : detail_::convert<T>(constexpr_forward<V>(v));
-  }
-
-# endif
-
-  // 20.6.3.6, modifiers
-  void reset() noexcept { clear(); }
-};
-
-
-template <class T>
-class optional<T&>
-{
-  static_assert( !std::is_same<T, nullopt_t>::value, "bad T" );
-  T* ref;
-
-public:
-
-  // 20.5.5.1, construction/destruction
-  constexpr optional() noexcept : ref(nullptr) {}
-
-  constexpr optional(nullopt_t) noexcept : ref(nullptr) {}
-
-  constexpr optional(T& v) noexcept : ref(detail_::static_addressof(v)) {}
-
-  optional(T&&) = delete;
-
-  constexpr optional(const optional& rhs) noexcept : ref(rhs.ref) {}
-
-  ~optional() = default;
-
-  // 20.5.5.2, mutation
-  optional& operator=(nullopt_t) noexcept {
-    ref = nullptr;
-    return *this;
-  }
-
-  template <typename U>
-  auto operator=(U&& rhs) noexcept
-  -> typename enable_if
-  <
-    is_same<typename decay<U>::type, optional<T&>>::value,
-    optional&
-  >::type
-  {
-    ref = rhs.ref;
-    return *this;
-  }
-
-  template <typename U>
-  auto operator=(U&& rhs) noexcept
-  -> typename enable_if
-  <
-    !is_same<typename decay<U>::type, optional<T&>>::value,
-    optional&
-  >::type
-  = delete;
-
-  void emplace(T& v) noexcept {
-    ref = detail_::static_addressof(v);
-  }
-
-  void emplace(T&&) = delete;
-
-
-  void swap(optional<T&>& rhs) noexcept
-  {
-    std::swap(ref, rhs.ref);
-  }
-
-  // 20.5.5.3, observers
-  constexpr T* operator->() const {
-    return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, ref);
-  }
-
-  constexpr T& operator*() const {
-    return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, *ref);
-  }
-
-  constexpr T& value() const {
-    return ref ? *ref : (throw bad_optional_access("bad optional access"), *ref);
-  }
-
-  explicit constexpr operator bool() const noexcept {
-    return ref != nullptr;
-  }
-
-  constexpr bool has_value() const noexcept {
-    return ref != nullptr;
-  }
-
-  template <class V>
-  constexpr typename decay<T>::type value_or(V&& v) const
-  {
-    return *this ? **this : detail_::convert<typename decay<T>::type>(constexpr_forward<V>(v));
-  }
-
-  // x.x.x.x, modifiers
-  void reset() noexcept { ref = nullptr; }
-};
-
-
-template <class T>
-class optional<T&&>
-{
-  static_assert( sizeof(T) == 0, "optional rvalue references disallowed" );
-};
-
-
-// 20.5.8, Relational operators
-template <class T> constexpr bool operator==(const optional<T>& x, const optional<T>& y)
-{
-  return bool(x) != bool(y) ? false : bool(x) == false ? true : *x == *y;
-}
-
-template <class T> constexpr bool operator!=(const optional<T>& x, const optional<T>& y)
-{
-  return !(x == y);
-}
-
-template <class T> constexpr bool operator<(const optional<T>& x, const optional<T>& y)
-{
-  return (!y) ? false : (!x) ? true : *x < *y;
-}
-
-template <class T> constexpr bool operator>(const optional<T>& x, const optional<T>& y)
-{
-  return (y < x);
-}
-
-template <class T> constexpr bool operator<=(const optional<T>& x, const optional<T>& y)
-{
-  return !(y < x);
-}
-
-template <class T> constexpr bool operator>=(const optional<T>& x, const optional<T>& y)
-{
-  return !(x < y);
-}
-
-
-// 20.5.9, Comparison with nullopt
-template <class T> constexpr bool operator==(const optional<T>& x, nullopt_t) noexcept
-{
-  return (!x);
-}
-
-template <class T> constexpr bool operator==(nullopt_t, const optional<T>& x) noexcept
-{
-  return (!x);
-}
-
-template <class T> constexpr bool operator!=(const optional<T>& x, nullopt_t) noexcept
-{
-  return bool(x);
-}
-
-template <class T> constexpr bool operator!=(nullopt_t, const optional<T>& x) noexcept
-{
-  return bool(x);
-}
-
-template <class T> constexpr bool operator<(const optional<T>&, nullopt_t) noexcept
-{
-  return false;
-}
-
-template <class T> constexpr bool operator<(nullopt_t, const optional<T>& x) noexcept
-{
-  return bool(x);
-}
-
-template <class T> constexpr bool operator<=(const optional<T>& x, nullopt_t) noexcept
-{
-  return (!x);
-}
-
-template <class T> constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept
-{
-  return true;
-}
-
-template <class T> constexpr bool operator>(const optional<T>& x, nullopt_t) noexcept
-{
-  return bool(x);
-}
-
-template <class T> constexpr bool operator>(nullopt_t, const optional<T>&) noexcept
-{
-  return false;
-}
-
-template <class T> constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept
-{
-  return true;
-}
-
-template <class T> constexpr bool operator>=(nullopt_t, const optional<T>& x) noexcept
-{
-  return (!x);
-}
-
-
-
-// 20.5.10, Comparison with T
-template <class T> constexpr bool operator==(const optional<T>& x, const T& v)
-{
-  return bool(x) ? *x == v : false;
-}
-
-template <class T> constexpr bool operator==(const T& v, const optional<T>& x)
-{
-  return bool(x) ? v == *x : false;
-}
-
-template <class T> constexpr bool operator!=(const optional<T>& x, const T& v)
-{
-  return bool(x) ? *x != v : true;
-}
-
-template <class T> constexpr bool operator!=(const T& v, const optional<T>& x)
-{
-  return bool(x) ? v != *x : true;
-}
-
-template <class T> constexpr bool operator<(const optional<T>& x, const T& v)
-{
-  return bool(x) ? *x < v : true;
-}
-
-template <class T> constexpr bool operator>(const T& v, const optional<T>& x)
-{
-  return bool(x) ? v > *x : true;
-}
-
-template <class T> constexpr bool operator>(const optional<T>& x, const T& v)
-{
-  return bool(x) ? *x > v : false;
-}
-
-template <class T> constexpr bool operator<(const T& v, const optional<T>& x)
-{
-  return bool(x) ? v < *x : false;
-}
-
-template <class T> constexpr bool operator>=(const optional<T>& x, const T& v)
-{
-  return bool(x) ? *x >= v : false;
-}
-
-template <class T> constexpr bool operator<=(const T& v, const optional<T>& x)
-{
-  return bool(x) ? v <= *x : false;
-}
-
-template <class T> constexpr bool operator<=(const optional<T>& x, const T& v)
-{
-  return bool(x) ? *x <= v : true;
-}
-
-template <class T> constexpr bool operator>=(const T& v, const optional<T>& x)
-{
-  return bool(x) ? v >= *x : true;
-}
-
-
-// Comparison of optional<T&> with T
-template <class T> constexpr bool operator==(const optional<T&>& x, const T& v)
-{
-  return bool(x) ? *x == v : false;
-}
-
-template <class T> constexpr bool operator==(const T& v, const optional<T&>& x)
-{
-  return bool(x) ? v == *x : false;
-}
-
-template <class T> constexpr bool operator!=(const optional<T&>& x, const T& v)
-{
-  return bool(x) ? *x != v : true;
-}
-
-template <class T> constexpr bool operator!=(const T& v, const optional<T&>& x)
-{
-  return bool(x) ? v != *x : true;
-}
-
-template <class T> constexpr bool operator<(const optional<T&>& x, const T& v)
-{
-  return bool(x) ? *x < v : true;
-}
-
-template <class T> constexpr bool operator>(const T& v, const optional<T&>& x)
-{
-  return bool(x) ? v > *x : true;
-}
-
-template <class T> constexpr bool operator>(const optional<T&>& x, const T& v)
-{
-  return bool(x) ? *x > v : false;
-}
-
-template <class T> constexpr bool operator<(const T& v, const optional<T&>& x)
-{
-  return bool(x) ? v < *x : false;
-}
-
-template <class T> constexpr bool operator>=(const optional<T&>& x, const T& v)
-{
-  return bool(x) ? *x >= v : false;
-}
-
-template <class T> constexpr bool operator<=(const T& v, const optional<T&>& x)
-{
-  return bool(x) ? v <= *x : false;
-}
-
-template <class T> constexpr bool operator<=(const optional<T&>& x, const T& v)
-{
-  return bool(x) ? *x <= v : true;
-}
-
-template <class T> constexpr bool operator>=(const T& v, const optional<T&>& x)
-{
-  return bool(x) ? v >= *x : true;
-}
-
-// Comparison of optional<T const&> with T
-template <class T> constexpr bool operator==(const optional<const T&>& x, const T& v)
-{
-  return bool(x) ? *x == v : false;
-}
-
-template <class T> constexpr bool operator==(const T& v, const optional<const T&>& x)
-{
-  return bool(x) ? v == *x : false;
-}
-
-template <class T> constexpr bool operator!=(const optional<const T&>& x, const T& v)
-{
-  return bool(x) ? *x != v : true;
-}
-
-template <class T> constexpr bool operator!=(const T& v, const optional<const T&>& x)
-{
-  return bool(x) ? v != *x : true;
-}
-
-template <class T> constexpr bool operator<(const optional<const T&>& x, const T& v)
-{
-  return bool(x) ? *x < v : true;
-}
-
-template <class T> constexpr bool operator>(const T& v, const optional<const T&>& x)
-{
-  return bool(x) ? v > *x : true;
-}
-
-template <class T> constexpr bool operator>(const optional<const T&>& x, const T& v)
-{
-  return bool(x) ? *x > v : false;
-}
-
-template <class T> constexpr bool operator<(const T& v, const optional<const T&>& x)
-{
-  return bool(x) ? v < *x : false;
-}
-
-template <class T> constexpr bool operator>=(const optional<const T&>& x, const T& v)
-{
-  return bool(x) ? *x >= v : false;
-}
-
-template <class T> constexpr bool operator<=(const T& v, const optional<const T&>& x)
-{
-  return bool(x) ? v <= *x : false;
-}
-
-template <class T> constexpr bool operator<=(const optional<const T&>& x, const T& v)
-{
-  return bool(x) ? *x <= v : true;
-}
-
-template <class T> constexpr bool operator>=(const T& v, const optional<const T&>& x)
-{
-  return bool(x) ? v >= *x : true;
-}
-
-
-// 20.5.12, Specialized algorithms
-template <class T>
-void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y)))
-{
-  x.swap(y);
-}
-
-
-template <class T>
-constexpr optional<typename decay<T>::type> make_optional(T&& v)
-{
-  return optional<typename decay<T>::type>(constexpr_forward<T>(v));
-}
-
-template <class X>
-constexpr optional<X&> make_optional(reference_wrapper<X> v)
-{
-  return optional<X&>(v.get());
-}
-
-
-} // namespace vital
-} // namespace kwiver
-
-
-namespace std {
-
-template < typename T >
-struct hash< kwiver::vital::optional< T > >
-{
-  typedef typename hash< T >::result_type result_type;
-  typedef kwiver::vital::optional< T > argument_type;
-
-  constexpr result_type operator()( argument_type const& arg ) const
-  {
-    return arg ? std::hash< T > {} ( *arg ) : result_type {};
-  }
-};
-
-template < typename T >
-struct hash< kwiver::vital::optional< T& > >
-{
-  typedef typename hash< T >::result_type result_type;
-  typedef kwiver::vital::optional< T& > argument_type;
-
-  constexpr result_type operator()( argument_type const& arg ) const
-  {
-    return arg ? std::hash< T > {} ( *arg ) : result_type {};
-  }
-};
-
-} // end namesoace
-
-
-# undef TR2_OPTIONAL_REQUIRES
-# undef TR2_OPTIONAL_ASSERTED_EXPRESSION
-
-# endif //_VITAL_INTERNAL_OPTIONAL_HPP___
diff --git a/vital/util/interval_map.h b/vital/util/interval_map.h
index a15da30f0c..f73a91fcb1 100644
--- a/vital/util/interval_map.h
+++ b/vital/util/interval_map.h
@@ -8,13 +8,13 @@
 #ifndef KWIVER_VITAL_UTIL_INTERVAL_MAP_H_
 #define KWIVER_VITAL_UTIL_INTERVAL_MAP_H_
 
-#include <vital/optional.h>
 #include <vital/range/iterator_range.h>
 #include <vital/util/interval.h>
 
 #include <initializer_list>
 #include <iterator>
 #include <map>
+#include <optional>
 #include <vector>
 
 namespace kwiver {
@@ -247,11 +247,11 @@ class interval_map
   /// Return the value, if any, mapped to the given point in key.
   ///
   /// Execution time is O(log n).
-  optional< ValueT >
+  std::optional< ValueT >
   at( KeyT key ) const
   {
     auto const it = find( key );
-    return ( it != cend() ) ? optional< ValueT >{ it->value } : nullopt;
+    return ( it != cend() ) ? std::optional< ValueT >{ it->value } : std::nullopt;
   }
 
   /// Set the value of the given interval to the given value.


Test patch:
diff --git a/arrows/klv/tests/test_klv_0601.cxx b/arrows/klv/tests/test_klv_0601.cxx
index 36163cd435..0569aafc75 100644
--- a/arrows/klv/tests/test_klv_0601.cxx
+++ b/arrows/klv/tests/test_klv_0601.cxx
@@ -10,6 +10,8 @@
 #include <arrows/klv/klv_0601.h>
 #include <arrows/klv/klv_1204.h>
 
+#include <optional>
+
 // ----------------------------------------------------------------------------
 int
 main( int argc, char** argv )
@@ -160,7 +162,7 @@ auto const expected_result = klv_local_set{
   { KLV_0601_ALTITUDE_ABOVE_GROUND_LEVEL,      kld{ 2150.0000000000000 } },
   { KLV_0601_RADAR_ALTIMETER,                  kld{ 2154.5000000000000 } },
   { KLV_0601_CONTROL_COMMAND,
-    klv_0601_control_command{ 5, "Fly to Waypoint 1", kv::nullopt } },
+    klv_0601_control_command{ 5, "Fly to Waypoint 1", std::nullopt } },
   { KLV_0601_CONTROL_COMMAND_VERIFICATION_LIST,
     std::vector< uint64_t >{ 3, 7 } },
   { KLV_0601_SENSOR_AZIMUTH_RATE,              kld{  1.0 } },
@@ -172,7 +174,7 @@ auto const expected_result = klv_local_set{
   { KLV_0601_COUNTRY_CODES,
     klv_0601_country_codes{
       KLV_0102_COUNTRY_CODING_METHOD_GENC_THREE_LETTER,
-      std::string{ "CAN" }, kv::nullopt, std::string{ "FRA" } } },
+      std::string{ "CAN" }, std::nullopt, std::string{ "FRA" } } },
   { KLV_0601_NUMBER_OF_NAVSATS_IN_VIEW,        uint64_t{ 7 } },
   { KLV_0601_POSITIONING_METHOD_SOURCE,
     std::set< klv_0601_positioning_method_source_bit >{
diff --git a/arrows/klv/tests/test_klv_1002.cxx b/arrows/klv/tests/test_klv_1002.cxx
index fa6d61da09..37b4ca6bf1 100644
--- a/arrows/klv/tests/test_klv_1002.cxx
+++ b/arrows/klv/tests/test_klv_1002.cxx
@@ -10,6 +10,8 @@
 #include <arrows/klv/klv_1002.h>
 #include <arrows/klv/klv_1202.h>
 
+#include <optional>
+
 // ----------------------------------------------------------------------------
 int
 main( int argc, char** argv )
@@ -50,10 +52,10 @@ auto const expected_result = klv_local_set{
       2, 0,
       { { 2, 2 },
         { 100.0, 105.0, 95.0, 100.0 } },
-      kv::nullopt,
+      std::nullopt,
       kld{ 1.0 },
       kld{ 2.0 },
-      kv::nullopt } } };
+      std::nullopt } } };
 
 // ----------------------------------------------------------------------------
 auto const input_bytes = klv_bytes_t{
diff --git a/arrows/klv/tests/test_klv_demuxer.cxx b/arrows/klv/tests/test_klv_demuxer.cxx
index 2d593ff5ca..4e9034354d 100644
--- a/arrows/klv/tests/test_klv_demuxer.cxx
+++ b/arrows/klv/tests/test_klv_demuxer.cxx
@@ -10,6 +10,8 @@
 
 #include <tests/test_gtest.h>
 
+#include <optional>
+
 namespace kv = kwiver::vital;
 
 // ----------------------------------------------------------------------------
@@ -215,8 +217,8 @@ TEST ( klv, demuxer_0601_special )
             { 1, KLV_0601_PAYLOAD_TYPE_ELECTRO_OPTICAL, "ACME VIS" } } },
         { KLV_0601_WAYPOINT_LIST,
           std::vector< klv_0601_waypoint_record >{
-            { 0, 1, kv::nullopt, kv::nullopt },
-            { 1, 2, kv::nullopt, kv::nullopt } } },
+            { 0, 1, std::nullopt, std::nullopt },
+            { 1, 2, std::nullopt, std::nullopt } } },
         { KLV_0601_WEAPON_FIRED, uint64_t{ 0xBA } },
         { KLV_0601_CONTROL_COMMAND_VERIFICATION_LIST,
           std::vector< uint64_t >{ 0 } },
@@ -262,9 +264,9 @@ TEST ( klv, demuxer_0601_special )
             { 3, KLV_0601_PAYLOAD_TYPE_ELECTRO_OPTICAL, "ACME VIS 2" } } },
         { KLV_0601_WAYPOINT_LIST,
           std::vector< klv_0601_waypoint_record >{
-            { 0, 1, kv::nullopt, kv::nullopt },
-            { 2, 3, kv::nullopt, kv::nullopt },
-            { 3, 4, kv::nullopt, kv::nullopt } } },
+            { 0, 1, std::nullopt, std::nullopt },
+            { 2, 3, std::nullopt, std::nullopt },
+            { 3, 4, std::nullopt, std::nullopt } } },
         { KLV_0601_CONTROL_COMMAND_VERIFICATION_LIST,
           std::vector< uint64_t >{ 1 } },
         { KLV_0601_SDCC_FLP,
diff --git a/arrows/serialize/json/klv/tests/test_load_save_klv.cxx b/arrows/serialize/json/klv/tests/test_load_save_klv.cxx
index 3b1eb1e722..946184a412 100644
--- a/arrows/serialize/json/klv/tests/test_load_save_klv.cxx
+++ b/arrows/serialize/json/klv/tests/test_load_save_klv.cxx
@@ -12,6 +12,7 @@
 #include <test_gtest.h>
 
 #include <fstream>
+#include <optional>
 #include <sstream>
 
 #include <cfloat>
@@ -133,10 +134,10 @@ klv_local_set const test_1002_set = {
       2, 0,
       { { 2, 2 },
         { 100.0, 105.0, 95.0, 100.0 } },
-      kv::nullopt,
+      std::nullopt,
       kld{ 1.0 },
       kld{ 2.0 },
-      kv::nullopt } },
+      std::nullopt } },
   { KLV_1002_GENERALIZED_TRANSFORMATION_LOCAL_SET, test_1202_set } };
 
 // ---------------------------------------------------------------------------
@@ -199,8 +200,8 @@ klv_local_set const test_0601_set = {
     klv_0601_country_codes{
       KLV_0102_COUNTRY_CODING_METHOD_GENC_THREE_LETTER,
       std::string{ "USA" },
-      kv::nullopt,
-      kv::nullopt } },
+      std::nullopt,
+      std::nullopt } },
   { KLV_0601_PAYLOAD_LIST,
     std::vector< klv_0601_payload_record >{
       { 2, KLV_0601_PAYLOAD_TYPE_ELECTRO_OPTICAL, "Camera" } } },
@@ -211,7 +212,7 @@ klv_local_set const test_0601_set = {
     std::vector< klv_0601_waypoint_record >{
       { 1, -3,
         std::set< klv_0601_waypoint_info_bit >{ KLV_0601_WAYPOINT_INFO_BIT_MODE },
-        kv::nullopt } } },
+        std::nullopt } } },
   { KLV_0601_MIIS_CORE_IDENTIFIER,
     klv_1204_miis_id{
       2,
@@ -222,8 +223,8 @@ klv_local_set const test_0601_set = {
   { KLV_0601_VIEW_DOMAIN,
     klv_0601_view_domain{
       klv_0601_view_domain_interval{ 30.0, 60.0 },
-      kv::nullopt,
-      kv::nullopt } },
+      std::nullopt,
+      std::nullopt } },
   { KLV_0601_RVT_LOCAL_SET, test_0806_set },
   { KLV_0601_VMTI_LOCAL_SET, test_0903_set },
   { KLV_0601_RANGE_IMAGE_LOCAL_SET, test_1002_set },
diff --git a/sprokit/tests/sprokit/pipeline/test_edge.cxx b/sprokit/tests/sprokit/pipeline/test_edge.cxx
index acb2726a05..a73ee536e0 100644
--- a/sprokit/tests/sprokit/pipeline/test_edge.cxx
+++ b/sprokit/tests/sprokit/pipeline/test_edge.cxx
@@ -23,6 +23,7 @@
 
 #include <boost/thread/thread.hpp>
 
+#include <optional>
 #include <memory>
 
 #define TEST_ARGS ()
@@ -553,7 +554,7 @@ IMPLEMENT_TEST(try_get_datum)
   time_point_t const start = time_clock_t::now();
 
   // This should be blocking.
-  kwiver::vital::optional<sprokit::edge_datum_t> const opt_datum = edge->try_get_datum(WAIT_DURATION);
+  std::optional<sprokit::edge_datum_t> const opt_datum = edge->try_get_datum(WAIT_DURATION);
 
   time_point_t const end = time_clock_t::now();
 
diff --git a/vital/util/tests/test_interval_map.cxx b/vital/util/tests/test_interval_map.cxx
index cf32a82d77..496df0f4ad 100644
--- a/vital/util/tests/test_interval_map.cxx
+++ b/vital/util/tests/test_interval_map.cxx
@@ -136,10 +136,10 @@ TEST ( interval_map, iterators )
 TEST ( interval_map, find_point )
 {
   using map_type = interval_map< float, int >;
-  using opt_type = kwiver::vital::optional< int >;
+  using opt_type = std::optional< int >;
 
   auto const empty_map = map_type{};
-  EXPECT_EQ( kwiver::vital::nullopt, empty_map.at( 0.0f ) );
+  EXPECT_EQ( std::nullopt, empty_map.at( 0.0f ) );
 
   auto const test_map = map_type{
     { { -finf, -100.0f }, -1 },
@@ -148,7 +148,7 @@ TEST ( interval_map, find_point )
     { { 10.0f, finf }, 2 }, };
 
   // Key with no value
-  EXPECT_EQ( kwiver::vital::nullopt, test_map.at( -1.0f ) );
+  EXPECT_EQ( std::nullopt, test_map.at( -1.0f ) );
 
   // Bottom of interval
   EXPECT_EQ( opt_type{ 0 }, test_map.at( 0.0f ) );
@@ -160,7 +160,7 @@ TEST ( interval_map, find_point )
   EXPECT_EQ( opt_type{ 2 }, test_map.at( 100.0f ) );
 
   // Top of interval
-  EXPECT_EQ( kwiver::vital::nullopt, test_map.at( 5.0f ) );
+  EXPECT_EQ( std::nullopt, test_map.at( 5.0f ) );
 
   // Between adjacent intervals
   EXPECT_EQ( opt_type{ 1 }, test_map.at( 1.0f ) );
@@ -171,7 +171,7 @@ TEST ( interval_map, find_point )
   // value of a given type (e.g. infinity, SIZE_MAX). Practically, unsure
   // whether this limitation is particularly pressing.
   EXPECT_EQ( opt_type{ -1 }, test_map.at( -finf ) );
-  EXPECT_EQ( kwiver::vital::nullopt, test_map.at( finf ) );
+  EXPECT_EQ( std::nullopt, test_map.at( finf ) );
 
   // NaN
   EXPECT_THROW( test_map.at( fnan ), std::invalid_argument );