     /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
     public mutating func encodeWeak<T : AnyObject & Encodable>(_ object: T, forKey key: Key) throws {
         try _box.encodeWeak(object, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: Bool?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: Int?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: Int8?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: Int16?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: Int32?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: Int64?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: UInt?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: UInt8?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: UInt16?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: UInt32?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: UInt64?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: Float?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: Double?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent(_ value: String?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
+    }
+
+    /// Encodes the given value for the given key if it is not `nil`.
+    ///
+    /// - parameter value: The value to encode.
+    /// - parameter key: The key to associate the value with.
+    /// - throws: `EncodingError.invalidValue` if the given value is invalid in the current context for this format.
+    public mutating func encodeIfPresent<T : Encodable>(_ value: T?, forKey key: Key) throws {
+        try _box.encodeIfPresent(value, forKey: key)
     }
 
     /// Stores a keyed encoding container for the given key and returns it.

    /// - returns: Whether the `Decoder` has an entry for the given key.
    func contains(_ key: Key) -> Bool

    /// Decodes a value of the given type for the given key.
    ///
    /// - parameter type: The type of value to decode.


    @_inlineable
    @_versioned
    internal func encodeNil(forKey key: Key) throws {
        fatalError("_KeyedEncodingContainerBase cannot be used directly.")
    }

    @_inlineable
    @_versioned
    internal func encode(_ value: Bool, forKey key: Key) throws {
        fatalError("_KeyedEncodingContainerBase cannot be used directly.")
    }
